Results 1 to 2 of 2

Thread: Help Please: Could not find schema information for the element

  1. #1

    Thread Starter
    Hyperactive Member jokerfool's Avatar
    Join Date
    Dec 2006
    Location
    Gold Coast, Australia
    Posts
    452

    Question Help Please: Could not find schema information for the element

    I don't actually know how to start this because I haven't touched the .NET for quite some time, usually this isn't an issue for me, but for the life of me I can't remember.

    2 files. 1 form and 1 XML

    XML:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Device>
        <Recipe>Axe</Recipe>
        <Rarity>Basic</Rarity>
        <Author>testuser</Author>
        <Information>Information here123</Information>
      </Device>
      <Device>
        <Recipe>Axe</Recipe>
        <Rarity>Basic</Rarity>
        <Author>testuser</Author>
        <Information>Information here123</Information>
      </Device>
      	</Table>
    When I only have one lot of information E.G.:

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Device>
        <Recipe>Axe</Recipe>
        <Rarity>Basic</Rarity>
        <Author>testuser</Author>
        <Information>Information here123</Information>
      </Device>
    </Table>

    And I run the application, it runs fine displaying the contents in the Datagrid. When I add a second set of information I get the error:

    Code:
    Could not find schema information for the element
    This is my form

    Code:
    Imports System.Xml
    Imports System.Data
    Public Class Form1
        Private WithEvents pd As New Printing.PrintDocument
        Private WithEvents ppd As New PrintPreviewDialog
        Private Property iChildFormNumber As Integer
        Dim ds As New DataSet
        Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Dim tr As New System.IO.StringReader(My.Resources.Recipes)
            ds.ReadXml(tr)
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub btnRecipesFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecipesFilter.Click
            ds.Tables(0).DefaultView.RowFilter = "[Recipe] like '%" & tbRecipes.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub btnRarity_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRarity.Click
            ds.Tables(0).DefaultView.RowFilter = "[Rarity] like '%" & tbRarity.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub btnAuthorFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAuthorFilter.Click
            ds.Tables(0).DefaultView.RowFilter = "[Author] like '%" & tbAuthor.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub btnInformationFilter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInformationFilter.Click
            ds.Tables(0).DefaultView.RowFilter = "[Information] like '%" & tbInformation.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub tbRecipes_TextChanged(sender As Object, e As EventArgs) Handles tbRecipes.TextChanged
            ds.Tables(0).DefaultView.RowFilter = "[Recipes] like '%" & tbRecipes.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub tbRarity_TextChanged(sender As Object, e As EventArgs) Handles tbRarity.TextChanged
            ds.Tables(0).DefaultView.RowFilter = "[Rarity] like '%" & tbRarity.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub tbAuthor_TextChanged(sender As Object, e As EventArgs) Handles tbAuthor.TextChanged
            ds.Tables(0).DefaultView.RowFilter = "[Author] like '%" & tbAuthor.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
        Private Sub tbInformation_TextChanged(sender As Object, e As EventArgs) Handles tbInformation.TextChanged
            ds.Tables(0).DefaultView.RowFilter = "[Information] like '%" & tbInformation.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
        End Sub
    
        Private Sub PrintToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles PrintToolStripMenuItem.Click
            ppd.Document = pd
            ppd.WindowState = FormWindowState.Maximized
            ppd.ShowDialog()
        End Sub
        Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs)
            ' this assumes that the selection will fit on a single page
            ' it gets rather more complicated if you want multipage
            e.Graphics.DrawString(My.Computer.Clipboard.GetDataObject.GetData("Text", True).ToString, DataGridView1.Font, Brushes.Black, New Point(0, 0))
        End Sub
        Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
            Dim startX As Integer = 50
            Dim startY As Integer = 50
    
            Dim sf As New StringFormat
            sf.Alignment = StringAlignment.Near
            sf.LineAlignment = StringAlignment.Center
    
            Dim cells() As DataGridViewCell = DataGridView1.SelectedCells.Cast(Of DataGridViewCell).OrderBy(Function(c) c.OwningRow.Index).ThenBy(Function(c) c.OwningColumn.Index).ToArray
    
            For x As Integer = 0 To cells.Count - 1
                Dim cell As DataGridViewCell = cells(x)
                e.Graphics.DrawRectangle(Pens.Black, New Rectangle(startX, startY, cell.Size.Width, cell.Size.Height))
                e.Graphics.DrawString(cell.Value.ToString, DataGridView1.Font, Brushes.Black, New Rectangle(startX, startY, cell.Size.Width, cell.Size.Height), sf)
                If x < cells.Count - 1 AndAlso cells(x + 1).OwningRow Is cells(x).OwningRow Then
                    startX += cell.Size.Width
                End If
                If x < cells.Count - 1 AndAlso cells(x + 1).OwningRow IsNot cells(x).OwningRow Then
                    startX = 50
                    startY += cell.Size.Height
                End If
            Next
    
        End Sub
    End Class
    I am in the process of adding the option so when I type into the search it scans through the text and starts displaying the results, hence why I have leave lines still in there e.g. :

    Code:
    ds.Tables(0).DefaultView.RowFilter = "[Recipe] like '%" & tbRecipes.Text & "%'"
            DataGridView1.DataSource = ds.Tables(0)
    Any ideas please.

    Thank you.

  2. #2
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: Help Please: Could not find schema information for the element

    Hi,

    I have never tried to read an XML file with a StringReader before so I thought I would give it a try to see what happens and, as expected, it threw an error, but not the one that you have described?

    My simple advice at this stage would be to get rid of the StringReader in the Load event and just read the XML file directly using the first overload of the ReadXML Method which expects only a filename. This then works fine with what you have shown.

    Hope that helps.

    Cheers,

    Ian
    Last edited by IanRyder; Aug 17th, 2014 at 08:54 AM. Reason: Usual Typo's

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width