Connecting Tech Pros Worldwide Help | Site Map

validate non W3C schemas in C# NET2.0

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 9th, 2008, 11:43 AM
Newbie
 
Join Date: Dec 2008
Age: 28
Posts: 4
Default validate non W3C schemas in C# NET2.0

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>

Last edited by Frinavale; December 9th, 2008 at 02:18 PM. Reason: added [code] tags
Reply
  #2  
Old December 9th, 2008, 11:52 AM
Newbie
 
Join Date: Dec 2008
Age: 28
Posts: 4
Default validating non W3C xml schema in c# .NET2.0

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
Reply
  #3  
Old December 9th, 2008, 02:18 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: Canada :)
Posts: 4,159
Default

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
Reply
  #4  
Old December 9th, 2008, 08:02 PM
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: Canada :)
Posts: 4,159
Default

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
Reply
  #5  
Old December 10th, 2008, 07:51 AM
Newbie
 
Join Date: Dec 2008
Age: 28
Posts: 4
Default Parse XDR xml file in C# .NET 2.0

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.

Last edited by Frinavale; December 10th, 2008 at 01:15 PM. Reason: added code tags
Reply
  #6  
Old December 10th, 2008, 01:51 PM
nukefusion's Avatar
Expert
 
Join Date: Mar 2008
Location: Essex, UK
Age: 29
Posts: 192
Default

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.
Reply
  #7  
Old December 10th, 2008, 06:53 PM
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 6,720
Default

I don't see any difference in the snippit provided with any other form of xml?
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.