Re: XML validation with multiple schemas



Continuing ...
My real-world multiple schemas are working out OK, but I cannot fathom the errors with a MSDN library example - using the XmlReader this time, and targetting .NET v2.0

I've copied the entire (very simple) VB.NET code I'm using, below. Sorry for the loss of indentation.

The sample code and data (XSD, XML) are at

The XML file is what's causing me the angst:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns="urn:dvdstore-schema" targetNamespace="urn:dvdstore-schema">
<xs:element name="dvd" type="xs:string" />
</xs:schema>
<pb:book price="7.99" xmlns:pb="urn:bookstore-schema">The Autobiography of Benjamin Franklin</pb:book>
<pd:dvd xmlns:pd="urn:dvdstore-schema">The Godfather</pd:dvd>
<pt:tape xmlns:pt="urn:tapestore-schema" xsi:schemaLocation="urn:tapestore-schema tape.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>Il Postino</pt:tape>

Can anyone point me to where the error is caused (line4, position 4 is the runtime error on reader.Read() - I don't see the problem)

--
Ian Thomas
' ------------------------------------
' XMLValidation5
' ------------------------------------
Imports System

Imports System.Xml

Imports System.Xml.Schema

Imports System.IO

Public Class Sample

Public Shared errno As Integer

Public Shared Sub Main()

ChDir("C:\")

Console.WriteLine("Current location: " & CurDir())

Dim sc As XmlSchemaSet = New XmlSchemaSet()

' Add the schema to the collection.

' original sample -------------------------

'sc.Add("urn:bookstore-schema", "books.xsd")

' -----------------------------------------

sc.Add(Nothing, "c:\book.xsd")

sc.Add(Nothing, "c:\tape.xsd")

Dim settings As XmlReaderSettings = New XmlReaderSettings()

settings.ValidationType = ValidationType.Schema

settings.Schemas = sc

errno = 0

' Try some XmlSchemavalidationFlags

settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ProcessInlineSchema

settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ReportValidationWarnings

settings.ValidationFlags = settings.ValidationFlags Or XmlSchemaValidationFlags.ProcessSchemaLocation

AddHandler settings.ValidationEventHandler, AddressOf ValidationCallBack

' Create the XmlReader object.

Dim reader As XmlReader = XmlReader.Create("c:\mixed.xml", settings)

Try

' Parse the file.

While reader.Read() ' Error in mixed.xml: There are multiple root elements. Line 4, position 4.

End While

Catch e As XmlException

Console.WriteLine("LineNumber = {0}", e.LineNumber)

Console.WriteLine("LinePosition = {0}", e.LinePosition)

Console.WriteLine("Message = {0}", e.Message)

Console.WriteLine("Source = {0}", e.Source)

Console.WriteLine("SourceUri = {0}", e.SourceUri)

End Try

End Sub

' Display any validation errors.

Private Shared Sub ValidationCallBack(ByVal sender As Object, ByVal e As ValidationEventArgs)

errno = errno + 1

Console.WriteLine(" Validation error " & errno.ToString & "- Severity: {0} - Message: {1}", e.Severity, e.Message)

End Sub

End Class




Relevant Pages

  • Re: UDP with VB.NET
    ... > Imports System.IO ... > Public Shared Event Sock_Error(ByVal Description As String) ... > Public Shared Sub UDP_Send(ByVal Host As String, ByVal Port As Integer, ...
    (microsoft.public.dotnet.framework.compactframework)
  • UDP with VB.NET
    ... ''' The Example will help u a fully understand UDP, Thread, and Encoding ... Imports System.IO ... Public Shared Event Sock_Error(ByVal Description As String) ... Public Shared Sub UDP_Send(ByVal Host As String, ByVal Port As Integer, ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Countdown
    ... > Imports System.Timers ... > Class App ... > Shared Startzeit As Short = 30 ... > Shared Sub Timeranzeige ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: C# Chr and Asc Function Equivalents - The Undocumented Truth!
    ... What is "correct" for mixed language projects and components is that which ... > Imports Microsoft.VisualBasic ... > Public Class Test ... > Shared Sub Main ...
    (microsoft.public.dotnet.languages.csharp)

Loading