Connecting Tech Pros Worldwide Forums | Help | Site Map

How can I validate an XML document with C#?

Doru Roman
Guest
 
Posts: n/a
#1: Mar 29 '06
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



Martin Honnen
Guest
 
Posts: n/a
#2: Mar 29 '06

re: How can I validate an XML document with C#?




Doru Roman wrote:

[color=blue]
> 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?[/color]

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
http://JavaScript.FAQTs.com/
Doru Roman
Guest
 
Posts: n/a
#3: Mar 29 '06

re: How can I validate an XML document with C#?


Thank you Martin. I will give it a try and eventually with more questions if
needed.


"Martin Honnen" <mahotrash@yahoo.de> wrote in message
news:en1OU%230UGHA.2360@TK2MSFTNGP09.phx.gbl...[color=blue]
>
>
> Doru Roman wrote:
>
>[color=green]
>> 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?[/color]
>
> 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
> http://JavaScript.FAQTs.com/[/color]


Doru Roman
Guest
 
Posts: n/a
#4: Mar 29 '06

re: How can I validate an XML document with C#?


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.

"Doru Roman" <doruroman@rogers.com> wrote in message
news:%236u7J11UGHA.2444@TK2MSFTNGP14.phx.gbl...[color=blue]
> Thank you Martin. I will give it a try and eventually with more questions
> if needed.
>
>
> "Martin Honnen" <mahotrash@yahoo.de> wrote in message
> news:en1OU%230UGHA.2360@TK2MSFTNGP09.phx.gbl...[color=green]
>>
>>
>> Doru Roman wrote:
>>
>>[color=darkred]
>>> 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?[/color]
>>
>> 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
>> http://JavaScript.FAQTs.com/[/color]
>
>[/color]


Cerebrus
Guest
 
Posts: n/a
#5: Mar 29 '06

re: How can I validate an XML document with C#?


Hi Doru Roman,
[color=blue][color=green]
>> 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?[/color][/color]

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".
[color=blue][color=green]
>> Can I create a schema from the XML menu Item?[/color][/color]

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

Hope this helps,

Regards,

Cerebrus.

Doru Roman
Guest
 
Posts: n/a
#6: Mar 29 '06

re: How can I validate an XML document with C#?


Thanks

"Cerebrus" <zorg007@sify.com> wrote in message
news:1143666147.657570.63400@u72g2000cwu.googlegro ups.com...[color=blue]
> Hi Doru Roman,
>[color=green][color=darkred]
>>> 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?[/color][/color]
>
> 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".
>[color=green][color=darkred]
>>> Can I create a schema from the XML menu Item?[/color][/color]
>
> Yes, that method is mentioned in point b) above.
>
> Hope this helps,
>
> Regards,
>
> Cerebrus.
>[/color]


Closed Thread