By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

validate non W3C schemas in C# NET2.0

P: 4
Can anyone tell me how to validate xml files which are not W3C complaint in C#.NET.
my xml file is of this format
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" ?>
  2. <Test xmlns="x-schema:MySchema.xml" xmlns:Test="x-schema:TestSchema.xml" xmlns:Testid="x-schema:TestIdSchema.xml">
  3.     <Info>
  4.         <Information name="Myname" address="2"/>        
  5.     </Info>
  6. </Test>
Dec 9 '08 #1
Share this Question
Share on Google+
6 Replies


P: 4
Can anyone tell me how to validate xml schemas in C# .NET 2.0 which are not W3C complaint
my xml fiel is like this:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" ?>
  2. <Test xmlns="x-schema:MySchema.xml" xmlns:Test="x-schema:TestSchema.xml" xmlns:Testid="x-schema:TestIdSchema.xml">
  3.     <Info>
  4.         <Information name="Myname" address="2"/>        
  5.     </Info>
  6. </Test>
Regards,
Sushma
Dec 9 '08 #2

Frinavale
Expert Mod 5K+
P: 9,731
XML files are validated using an XML schema.

(Definition for XML schema: A schema is a way to describe and validate data in an XML environment)

A schema is a model for describing the structure of information...

Use an instance of the XmlSchemaValidator class to validate XML in C#.

-Frinny
Dec 9 '08 #3

Frinavale
Expert Mod 5K+
P: 9,731
Sushma, please do not double post your question.
It makes it hard for you to get an answer to your question.
When you have the time please read over the rules of the forum outlined in the Posting Guidelines, especially the section labeled Do Not Double Post Your Question.

I have merged your threads together into one thread.

-Moderator Frinny
Dec 9 '08 #4

P: 4
Frinavale,
XmlSchemaValidator is for XSD file validation and my XML is of type XDR. I have used XMLValidatingReader to validate this eventhough it is obselate in .NET 2.0 as
XMLSchemaSet doesnt support XDR format .
Following is my input Test.xml
Expand|Select|Wrap|Line Numbers
  1.     <?xml version="1.0" ?>
  2.    <Test xmlns="x-schema:MySchema.xml" xmlns:Test="x-schema:TestSchema.xml" xmlns:Testid="x-schema:TestIdSchema.xml">
  3.       <Info>
  4.            <Information name="Myname" address="2"/>        
  5.        </Info>
  6.    </Test>
  7.  
validation part i have done like this:
Expand|Select|Wrap|Line Numbers
  1.             XmlSchemaCollection xsc = new XmlSchemaCollection();
  2.             xsc.Add("x-schema:MySchema.xml", @"C:\MySchema.xml");
  3.             xsc.Add("x-schema:TestSchema.xml", @"C:\TestSchema.xml");
  4.              XmlTextReader tr = new XmlTextReader(@"C:\Test.xml");
  5.             XmlValidatingReader vr = new XmlValidatingReader(tr);
  6.             vr.ValidationType = ValidationType.XDR;
  7.             vr.Schemas.Add(xsc);
  8.             vr.ValidationEventHandler += new ValidationEventHandler(ValidationHandler);
  9.             while (vr.Read()) ;
  10.  
I want to read attribute values of "name" and "address" from input xml. Please answer how to proceed further.
can i use XMLDocument to do this using "SelectSingleNode" and "Attributes.GetNamedItem"? for this i need to assign validated schemas to XMLDocument object. but XMLDocument object uses XMLSchemaSet while XmlValidatingReader uses XmlSchemaCollection.

Please send me sample code to parse this XML document.
Dec 10 '08 #5

nukefusion
Expert 100+
P: 221
Rather than continuing with the obsoleted XDR format is there any reason why you cannot convert your XDR into an XSD? You could then use the updated methods. I believe there are tools that can help you to do this.
Dec 10 '08 #6

Plater
Expert 5K+
P: 7,872
I don't see any difference in the snippit provided with any other form of xml?
Dec 10 '08 #7

Post your reply

Sign in to post your reply or Sign up for a free account.