I want to validate xml file with an xsd. It's already work when i put an incorect type but it's doesn't work when i delete row in my xml document. How do this?
<Test>
<TestNode1>1</TestNode1>
<TestNode2>true</TestNode2>
<TestNode3>true</TestNode3>
<TestNode4>true</TestNode4>
<TestNode5>true</TestNode5>
</Test>
<xs:element name="Test">
<xs:complexType>
<xs:sequence>
<xs:element name="TestNode1" type="xs:boolean"/>
<xs:element name="TestNode2" type="xs:boolean"/>
<xs:element name="TestNode3" type="xs:boolean"/>
<xs:element name="TestNode4" type="xs:boolean"/>
<xs:element name="TestNode5" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
When i remove the row who contains testnode4 for exemple... and when i use this =>
XmlReaderSettings xmlSettings = new XmlReaderSettings();
xmlSettings.IgnoreWhitespace = true;
xmlSettings.Schemas = new System.Xml.Schema.XmlSchemaSet();
xmlSettings.Schemas.Add(null, xsdUri);
xmlSettings.ValidationType = ValidationType.Schema;
using (var xmlStream = File.OpenRead(xmlUri))
{
var xmlFile = XmlReader.Create(xmlStream, xmlSettings);
while (xmlFile.Read()) { }
}
It's work but i don't want this.I want to get error when row is missed.
Thanks.
As you can see here http://www.w3schools.com/schema/el_sequence.asp .
The sequence element specifies that the child elements must appear in a sequence. Each child element can occur from 0 to any number of times.
If you want your element to be present every time, you have to specify a minOccurs attribute.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.