Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

xml validation issue

$
0
0

Hi,

below is the sample code i am using,

xsd:

<?xml version="1.0" encoding="UTF-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"><xs:element name="UsersList"><xs:complexType><xs:sequence><xs:element name="User"><xs:complexType><xs:sequence><xs:element ref="Name" /><xs:element ref="BirthTime" /></xs:sequence></xs:complexType></xs:element></xs:sequence></xs:complexType></xs:element><xs:element name = "Name"><xs:simpleType><xs:restriction base = "xs:string"><xs:pattern value="[a-zA-Z0-9]*"/></xs:restriction></xs:simpleType></xs:element><xs:element name="BirthTime"><xs:simpleType><xs:restriction base="xs:string"><xs:pattern value="(0[0-9]|[1][0-9]|2[0-3]):[0-5][0-9]"/></xs:restriction></xs:simpleType></xs:element></xs:schema>

xml:

<?xml version="1.0" encoding="utf-8"?><UsersList><User><Name>sam</Name><BirthTime>20:11</BirthTime></User><User><Name>wit</Name><BirthTime>10:11</BirthTime></User></UsersList>

c# code to validate

XmlSchemaSet schemas = new XmlSchemaSet();
                schemas.Add("", @"D:\XmlTesting\user.xsd");

                XDocument doc = XDocument.Load(@"D:\XmlTesting\user.xml");
                string msg = "";
                doc.Validate(schemas, (o, es) =>
                {
                    msg += es.Message + Environment.NewLine;
                });

                MessageBox.Show(msg == "" ? "Document is valid" : "Document invalid: " + msg);

when i try to validate, i am getting the following error,

The element 'UsersList' has invalid child element 'User
please advice me what am i doing wrong.


loving dotnet


Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>