Re: XML validation with multiple schemas
- From: "gxdata" <gxdata@xxxxxxxxx>
- Date: Wed, 30 Jan 2008 16:47:35 +0900
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
- References:
- XML validation with multiple schemas
- From: gxdata
- Re: XML validation with multiple schemas
- From: Martin Honnen
- Re: XML validation with multiple schemas
- From: gxdata
- XML validation with multiple schemas
- Prev by Date: Re: XML fragment - syntax error
- Next by Date: A7Soft announced JExamXML release
- Previous by thread: Re: XML validation with multiple schemas
- Next by thread: A7Soft announced JExamXML release
- Index(es):
Relevant Pages
|
Loading