I did some xml Xsd validation according to following method: Xml validation using XSD schema
.......................................................
XmlReaderSettings settings = new XmlReaderSettings();
settings.Schemas.Add(null, xsdFilePath);
settings.ValidationType = ValidationType.Schema;
settings.ValidationEventHandler += new System.Xml.Schema.ValidationEventHandler(settings_ValidationEventHandler);
XmlDocument document = new XmlDocument();
document.Load(xmlFilePath);
XmlReader rdr = XmlReader.Create(new StringReader(document.InnerXml), settings);
while (rdr.Read())
{
}
...........................................................
and it gives me error saying: "The 'ref' attribute cannot be present"
my XSD looks like :
...........
<xs:element name="totals" minOccurs="0" ref="DocTotal"/>
..................................
<xs:element name="DocTotal">
<xs:complexType>
<xs:sequence>
<xs:element name="totalQty" minOccurs="0" type="xs:decimal"/>
<xs:element name="totalTax" minOccurs="0" type="xs:decimal"/>
</xs:sequence>
<xs:attribute name="id" type="xs:string" use="required"/>
</xs:complexType>
</xs:element>
and my xml looks like:
<totals>
<totalQty>800</totalQty>
<totalTax>0.00<totalTax>
</totals>
I believe this error occurs because of the both "name" and "ref": attributes exists in same elements: however I think this is not wrong in XSD(appreciate your comments on this): in this case is there any way to validate this XSD with xml: