Hi,
My code won't validate the xml document.
I'm using vb.net.
In the IDE I can use the schema to validate the XML. But when I use
XmlValidatingReader in code it does not pick any restrictions.
eg. in the following schema I want one and only one 'Header' element,
and I want a 'Message' element to be within a Messages element as
'Messages' is a collection of 'Message'.
If I change these in the IDE (when I've pulled them into the project)
the validation works. How can I do this through code.
Thanks in advance.
XSD File
---------
<?xml version="1.0" encoding="utf-8"?>
<schema id="DataTransfer" targetNamespace="http://www.Test.com"
xmlns:idtdt="http://www.Test.com"
xmlns="http://www.w3.org/2001/XMLSchema">
<!-- PACKAGE DOCUMENT -->
<element name="Doc">
<complexType>
<!-- Header Information -->
<sequence>
<element name="Header" maxOccurs="1" minOccurs="1">
<complexType>
<attribute name="FileName" type="string"
use="required" />
</complexType>
</element>
<!-- A collection of zero or more Messages -->
<element name="Messages" maxOccurs="1">
<complexType>
<sequence>
<!-- A Message -->
<element name="Message"
maxOccurs="unbounded">
<complexType>
<sequence>
<!-- A collection of zero or
more Parameters -->
<element name="Value"
type="string" />
</sequence>
<attribute name="MessageID"
type="string" use="required" />
</complexType>
</element>
</sequence>
</complexType>
</element>
</sequence>
</complexType>
<key name="PackageDocKey1">
<selector xpath=".//Message" />
<field xpath="@MessageID" />
</key>
<key name="PackageDocKey2">
<selector xpath="./Messages/Parameters/Parameter" />
<field xpath="@Name" />
</key>
</element>
<!-- Process Status Enumeration -->
</schema>
XML File
--------
<?xml version="1.0" encoding="utf-8" ?>
<Doc xmlns="http://www.Test.com">
<!-- Header is a once only entry -->
<Header FileName ="ZZZ.txt"></Header>
<!-- Messages is a collection of (0 or many) Message -->
<Messages>
<Message MessageID ="1">
<!-- Value is a once only entry -->
<Value>TEST1</Value>
</Message>
<Message MessageID ="2">
<Value>TEST4</Value>
</Message>
<Message MessageID ="3">
<Value>TEST3</Value>
</Message>
</Messages>
</Doc>