all groups > dotnet xml > march 2006 >
You're in the

dotnet xml

group:

How can I validate an XML document with C#?


How can I validate an XML document with C#? Doru Roman
3/29/2006 11:27:16 AM
dotnet xml: Hi,

I am a beginner and I try to understand how can I use C# and Netframework to
validate an XML document. Is XSD a solution? How?

Thanks,
Doru

Re: How can I validate an XML document with C#? Cerebrus
3/29/2006 1:02:27 PM
Hi Doru Roman,

[quoted text, click to view]

In Solution Explorer, right click the project name and then choose Add
-> Add Existing item... then select your XML file.

2. To create your XML Schema :

a) Manually method : In Solution Explorer, right click the project name
and then choose Add -> Add New item... then select "XML Schema"
b) Automatic method : Once your XML file is opened, open the XML menu
at the top, and choose "Create schema".

[quoted text, click to view]

Yes, that method is mentioned in point b) above.

Hope this helps,

Regards,

Cerebrus.
Re: How can I validate an XML document with C#? Doru Roman
3/29/2006 1:19:15 PM
Thank you Martin. I will give it a try and eventually with more questions if
needed.


[quoted text, click to view]

Re: How can I validate an XML document with C#? Doru Roman
3/29/2006 2:46:56 PM
In fact I have some questions as I got stuck.
I have an XML document. What is next? How do I bring the XML document into
my C# project so that I can create an XSD schema? Can I create a schema from
the XML menu Item?
Afterwards I will try to write the code to validate the document, but I need
help to get to this point.

[quoted text, click to view]

Re: How can I validate an XML document with C#? Doru Roman
3/29/2006 5:29:15 PM
Thanks

[quoted text, click to view]

Re: How can I validate an XML document with C#? Martin Honnen
3/29/2006 6:41:04 PM


[quoted text, click to view]


[quoted text, click to view]

The .NET framework supports validation against a DTD or against an XDR
schema (deprecated) or against W3C XSD schema(s).
With .NET 1.x you would use XmlValidatingReader to do the validation,
with .NET 2.0 you would create an XmlReader with the proper
XmlReaderSettings for the validation you want.
See
<http://samples.gotdotnet.com/quickstart/howto/doc/Xml/ValidationReadingXML.aspx>
for .NET 1.x and
<http://www.asp.net/quickstart/howto/doc/Xml/ValidationReadingXML.aspx>
for .NET 2.0.


--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button