0

I have this xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
  <xsd:element name="F">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element maxOccurs="unbounded" name="A" />
      </xsd:sequence>
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

This xml is valid, but it is wrong

<F><F>
<A/>
</F></F>

I have to valid only this xml

<F>
   <A/>
</F>

How to do it in xsd?

C# code

XmlDocument xml = new XmlDocument();
using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(xml)))
    {
      xml.Load(ms);
    }

XmlSchemaSet schemas = new XmlSchemaSet();
schemas.Add("", xsdpath);
XDocument _xml = XDocument.Parse(xml.OuterXml);
_xml.Validate(schemas, (o, e) =>{});
  • Is this a duplicate? [XDocument.Validate is always successful](https://stackoverflow.com/q/17232575/3744182). – dbc Mar 27 '17 at 06:29
  • hm...not sure... you think that problem in c# validation code, do you? –  Mar 27 '17 at 06:34

1 Answers1

0

Result.

Validate() catches only errors, not warnings.

xmlReader has more options to check xml by xsd

If xml and xsd have different namespaces, validate() will be always true. To fix it you should remove namespaces from both files or write the same namespace.