473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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>
Dec 9 '08 #1
6 2620
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
9,735 Expert Mod 8TB
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
9,735 Expert Mod 8TB
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
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
221 Expert 100+
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
7,872 Expert 4TB
I don't see any difference in the snippit provided with any other form of xml?
Dec 10 '08 #7

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

Similar topics

8
by: johnsocs | last post by:
How do you validate the following XML document, I'm having problems with element 'one' with the attribute xsi:type="xsd:string" <?xml version="1.0" encoding="UTF-8"?> <zero...
0
by: johnsocs | last post by:
All I'm trying to write an xml schema for the following xml from the google web service api. In the schema I'm not sure how to describe the soapenv:encodingStyle attribute. Thanks. <?xml...
1
by: Ron Rohrssen | last post by:
I've been working on learning XML schemas and trying to make use of the MS classes for validating data against a schema. So, I've been trying to work through some simple schemas and instances....
9
by: Rob Mayo | last post by:
I have a bunch of XSD files in my assembly as embedded content that are read out via reflection and streams. My app creates the XML on the fly, and I want to validate it using the schema files...
1
by: aevans1108 | last post by:
Greetings All If this is the wrong place to post this question, please give me a push in the right direction. Thanks. I know there has to be a simpler way to do this, but this is as simple a...
6
by: LesleyW | last post by:
Hi Apologies if this is a really dumb question, but being new to XML and Schemas, I wonder if giving the namespace for eg xsd or xsi as a website address means that the user has to be online...
3
by: ciaran.mchale | last post by:
Hi folks, I downloaded the binary version of Xerces C++ 2.7.0 for Windows and am using it to help me get up to speed with XML and XML Schema. So please excuse me if this is a "novice" question....
6
by: Jonny | last post by:
Hi, I'm trying to validate my xml against a xsd but I can't get it to work. Originally, I wanted to validate an xml string but since I didn't get that to work I tried to validate an xml file...
0
by: Marc Scheuner | last post by:
Folks, I'm faced with a dilemma here - I have an XML document and for part of it, I have an XSD schema to validate it - but not for the rest of it. Can I still validate at least part of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.