validate non W3C schemas in C# NET2.0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sushmaraghu
    New Member
    • Dec 2008
    • 4

    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
    [code=xml]
    <?xml version="1.0" ?>
    <Test xmlns="x-schema:MySchema .xml" xmlns:Test="x-schema:TestSche ma.xml" xmlns:Testid="x-schema:TestIdSc hema.xml">
    <Info>
    <Information name="Myname" address="2"/>
    </Info>
    </Test>[/code]
    Last edited by Frinavale; Dec 9 '08, 03:18 PM. Reason: added [code] tags
  • sushmaraghu
    New Member
    • Dec 2008
    • 4

    #2
    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:
    [code=xml]
    <?xml version="1.0" ?>
    <Test xmlns="x-schema:MySchema .xml" xmlns:Test="x-schema:TestSche ma.xml" xmlns:Testid="x-schema:TestIdSc hema.xml">
    <Info>
    <Information name="Myname" address="2"/>
    </Info>
    </Test>[/code]

    Regards,
    Sushma

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      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 XmlSchemaValida tor class to validate XML in C#.

      -Frinny

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        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

        Comment

        • sushmaraghu
          New Member
          • Dec 2008
          • 4

          #5
          Parse XDR xml file in C# .NET 2.0

          Frinavale,
          XmlSchemaValida tor is for XSD file validation and my XML is of type XDR. I have used XMLValidatingRe ader to validate this eventhough it is obselate in .NET 2.0 as
          XMLSchemaSet doesnt support XDR format .
          Following is my input Test.xml
          [code=xml]
          <?xml version="1.0" ?>
          <Test xmlns="x-schema:MySchema .xml" xmlns:Test="x-schema:TestSche ma.xml" xmlns:Testid="x-schema:TestIdSc hema.xml">
          <Info>
          <Information name="Myname" address="2"/>
          </Info>
          </Test>
          [/code]
          validation part i have done like this:
          [code=c#]
          XmlSchemaCollec tion xsc = new XmlSchemaCollec tion();
          xsc.Add("x-schema:MySchema .xml", @"C:\MySchema.x ml");
          xsc.Add("x-schema:TestSche ma.xml", @"C:\TestSchema .xml");
          XmlTextReader tr = new XmlTextReader(@ "C:\Test.xm l");
          XmlValidatingRe ader vr = new XmlValidatingRe ader(tr);
          vr.ValidationTy pe = ValidationType. XDR;
          vr.Schemas.Add( xsc);
          vr.ValidationEv entHandler += new ValidationEvent Handler(Validat ionHandler);
          while (vr.Read()) ;
          [/code]
          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 "SelectSingleNo de" and "Attributes.Get NamedItem"? for this i need to assign validated schemas to XMLDocument object. but XMLDocument object uses XMLSchemaSet while XmlValidatingRe ader uses XmlSchemaCollec tion.

          Please send me sample code to parse this XML document.
          Last edited by Frinavale; Dec 10 '08, 02:15 PM. Reason: added code tags

          Comment

          • nukefusion
            Recognized Expert New Member
            • Mar 2008
            • 221

            #6
            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.

            Comment

            • Plater
              Recognized Expert Expert
              • Apr 2007
              • 7872

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

              Comment

              Working...