how to write XDR

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PA

    how to write XDR

    My dream XML will look like as follows:

    <?xml version="1.0"?>
    <bk:bookList xmlns:bk="urn:B ookSampleSchema .xdr">
    <book>
    <title>Doe's Book</title>
    <author>J Doe</author>
    <year>2002</year>
    </book>
    <book>
    <title>Sam's Book</title>
    <author>Sam</author>
    <year>2003</year>
    </book>
    </bk:bookList>

    and my XDR schema is:

    <Schema name="test_sche ma"
    xmlns="urn:sche mas-microsoft-com:xml-data"
    xmlns:dt="urn:s chemas-microsoft-com:datatypes">

    <ElementType name="title" content="textOn ly" model="closed"/>
    <ElementType name="author" content="textOn ly" model="closed"/>
    <ElementType name="year" content="textOn ly" model="closed"/>

    <ElementType name="book" content="eltOnl y" model="closed">
    <element type="title" minOccurs="1" maxOccurs="1"/>
    <element type="author" minOccurs="1" maxOccurs="1"/>
    <element type="year" minOccurs="1" maxOccurs="1"/>
    </ElementType>

    <ElementType name="bookList" content="eltOnl y" model="closed">
    <element type="book" minOccurs="0" maxOccurs="*"/>
    </ElementType>
    </Schema>

    I am using XMLValidatingRe ader to validate above xml. It fails if I
    don't mention bk before book, title etc. elements.

    Can anyone tell me what is the valid XDR for above XML?

    Thanks in advance.

    Pratibha
  • Dino Chiesa [Microsoft]

    #2
    Re: how to write XDR

    why are you using XDR? XDR was Microsoft's implementation of an early
    working draft of the XML Schema specification. In .NET, XDR is supported
    primarily for backward compatibility. In general you should be using XML
    Schema, which is now final.

    Using the xsd.exe utility included in the .NET SDK, you can infer a schema
    from a document.
    The schema I get from your document is:

    <xs:schema id="bookList" targetNamespace ="urn:BookSampl eSchema.xdr"
    xmlns:mstns="ur n:BookSampleSch ema.xdr" xmlns="urn:Book SampleSchema.xd r"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
    attributeFormDe fault="qualifie d" elementFormDefa ult="qualified" >
    <xs:element name="bookList" msdata:IsDataSe t="true" msdata:Prefix=" bk">
    <xs:complexType >
    <xs:choice maxOccurs="unbo unded">
    <xs:element name="book" form="unqualifi ed">
    <xs:complexType >
    <xs:sequence>
    <xs:element name="title" form="unqualifi ed" type="xs:string "
    minOccurs="0" />
    <xs:element name="author" form="unqualifi ed" type="xs:string "
    minOccurs="0" />
    <xs:element name="year" form="unqualifi ed" type="xs:string "
    minOccurs="0" />
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>





    "PA" <pratibhaa@jvc. co.uk> wrote in message
    news:f7b9f4bb.0 405170344.152f3 eab@posting.goo gle.com...[color=blue]
    > My dream XML will look like as follows:
    >
    > <?xml version="1.0"?>
    > <bk:bookList xmlns:bk="urn:B ookSampleSchema .xdr">
    > <book>
    > <title>Doe's Book</title>
    > <author>J Doe</author>
    > <year>2002</year>
    > </book>
    > <book>
    > <title>Sam's Book</title>
    > <author>Sam</author>
    > <year>2003</year>
    > </book>
    > </bk:bookList>
    >
    > and my XDR schema is:
    >
    > <Schema name="test_sche ma"
    > xmlns="urn:sche mas-microsoft-com:xml-data"
    > xmlns:dt="urn:s chemas-microsoft-com:datatypes">
    >
    > <ElementType name="title" content="textOn ly" model="closed"/>
    > <ElementType name="author" content="textOn ly" model="closed"/>
    > <ElementType name="year" content="textOn ly" model="closed"/>
    >
    > <ElementType name="book" content="eltOnl y" model="closed">
    > <element type="title" minOccurs="1" maxOccurs="1"/>
    > <element type="author" minOccurs="1" maxOccurs="1"/>
    > <element type="year" minOccurs="1" maxOccurs="1"/>
    > </ElementType>
    >
    > <ElementType name="bookList" content="eltOnl y" model="closed">
    > <element type="book" minOccurs="0" maxOccurs="*"/>
    > </ElementType>
    > </Schema>
    >
    > I am using XMLValidatingRe ader to validate above xml. It fails if I
    > don't mention bk before book, title etc. elements.
    >
    > Can anyone tell me what is the valid XDR for above XML?
    >
    > Thanks in advance.
    >
    > Pratibha[/color]


    Comment

    • P A

      #3
      Re: how to write XDR

      OK. I am now using XSD. Here is my new xml file.

      <?xml version="1.0"?>
      <bk:bookList xmlns:bk="urn:B ookSample.xsd">
      <book>
      <title>Doe's Book</title>
      <author>J Doe</author>
      <year>2002</year>
      </book>
      <book>
      <title>Sam's Book</title>
      <author>Sam</author>
      <year>2003</year>
      </book>
      </bk:bookList>

      I used XSD.exe to create XSD file. This is what I got

      <?xml version="1.0" encoding="utf-8"?>
      <xs:schema id="bookList" targetNamespace ="urn:BookSampl e.xsd"
      xmlns:mstns="ur n:BookSample.xs d" xmlns="urn:Book Sample.xsd"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
      attributeFormDe fault="qualifie d" elementFormDefa ult="qualified" >
      <xs:element name="bookList" msdata:IsDataSe t="true"
      msdata:Locale=" en-GB" msdata:Prefix=" bk">
      <xs:complexType >
      <xs:choice maxOccurs="unbo unded">
      <xs:element name="book" form="unqualifi ed">
      <xs:complexType >
      <xs:sequence>
      <xs:element name="title" form="unqualifi ed"
      type="xs:string " minOccurs="0" />
      <xs:element name="author" form="unqualifi ed"
      type="xs:string " minOccurs="0" />
      <xs:element name="year" form="unqualifi ed"
      type="xs:string " minOccurs="0" />
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:choice>
      </xs:complexType>
      </xs:element>
      </xs:schema>

      My .NET code looks like as follows:

      public function XMLValidattor() as Boolean
      Dim myXMLDoc As New XmlDocument()
      Dim myXMLNode As XmlElement
      Dim myXMLReader As XmlReader
      Dim sXMLData As String

      myXMLDoc.Load(S erver.MapPath(" BookSample.xml" ))

      ' validate xml first
      Dim TR As New XmlTextReader(N ew StringReader(my XMLDoc.OuterXml ))
      Dim VR As XmlValidatingRe ader = New XmlValidatingRe ader(TR)

      VR.Schemas.Add( "urn:Root.x dr", Server.MapPath( "BookSample.xsd "))
      VR.ValidationTy pe = ValidationType. Schema
      sErrMsg = ""
      AddHandler VR.ValidationEv entHandler, AddressOf
      ValidationCallB ack
      While VR.Read
      End While
      VR.Close()
      TR.Close()
      If sErrMsg <> "" Then
      Return False
      Else
      Return True
      End If

      Public Sub ValidationCallB ack(ByVal sender As Object, ByVal args As
      ValidationEvent Args)
      sErrMsg = args.Message
      End Sub

      When I run this I get following error:

      System.Xml.Sche ma.XmlSchemaExc eption: The attribute targetNamespace does
      not match the designated namespace URI. An error occurred at
      file:///c:/inetpub/wwwroot/CMService/BookSample.xsd, (2, 2).
      at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption
      e, XmlSeverityType severity)
      at System.Xml.Sche ma.Compiler.Sen dValidationEven t(String code,
      XmlSchemaObject source)
      at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
      targetNamespace , Compositor compositor)
      at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
      targetNamespace )
      at System.Xml.Sche ma.Compiler.Com pile(XmlSchema schema, String
      targetNamespace , SchemaInfo schemaInfo)
      at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection
      collection, XmlNameTable nameTable, SchemaNames schemaNames,
      ValidationEvent Handler validationEvent Handler, String targetNamespace ,
      SchemaInfo schemaInfo, Boolean compileContentM odel, XmlResolver
      resolver)
      at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, SchemaInfo
      schemaInfo, XmlSchema schema, Boolean compile, XmlResolver resolver)
      at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, XmlReader
      reader, XmlResolver resolver)
      at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, String uri)
      at CMService.CMSer vice.XMLReading WithXDR() in
      C:\Inetpub\wwwr oot\CMService\C MService.asmx.v b:line 674


      What's wrong now?

      Thanks in advance.

      Pratibha


      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      • Kirk Allen Evans [MSFT]

        #4
        Re: how to write XDR

        The targetNamespace you have still refers to the XDR schema's namespace.

        Change this line:
        VR.Schemas.Add( "urn:Root.x dr", Server.MapPath( "BookSample.xsd "))

        to this line:
        VR.Schemas.Add( "urn:BookSample .xsd", Server.MapPath( "BookSample.xsd "))


        --
        Kirk Allen Evans


        -- This posting is provided "AS IS" with no warranties, and confers no
        rights.

        "P A" <dotnet@xml.co. uk> wrote in message
        news:uAcDpCCPEH A.644@tk2msftng p13.phx.gbl...[color=blue]
        > OK. I am now using XSD. Here is my new xml file.
        >
        > <?xml version="1.0"?>
        > <bk:bookList xmlns:bk="urn:B ookSample.xsd">
        > <book>
        > <title>Doe's Book</title>
        > <author>J Doe</author>
        > <year>2002</year>
        > </book>
        > <book>
        > <title>Sam's Book</title>
        > <author>Sam</author>
        > <year>2003</year>
        > </book>
        > </bk:bookList>
        >
        > I used XSD.exe to create XSD file. This is what I got
        >
        > <?xml version="1.0" encoding="utf-8"?>
        > <xs:schema id="bookList" targetNamespace ="urn:BookSampl e.xsd"
        > xmlns:mstns="ur n:BookSample.xs d" xmlns="urn:Book Sample.xsd"
        > xmlns:xs="http://www.w3.org/2001/XMLSchema"
        > xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
        > attributeFormDe fault="qualifie d" elementFormDefa ult="qualified" >
        > <xs:element name="bookList" msdata:IsDataSe t="true"
        > msdata:Locale=" en-GB" msdata:Prefix=" bk">
        > <xs:complexType >
        > <xs:choice maxOccurs="unbo unded">
        > <xs:element name="book" form="unqualifi ed">
        > <xs:complexType >
        > <xs:sequence>
        > <xs:element name="title" form="unqualifi ed"
        > type="xs:string " minOccurs="0" />
        > <xs:element name="author" form="unqualifi ed"
        > type="xs:string " minOccurs="0" />
        > <xs:element name="year" form="unqualifi ed"
        > type="xs:string " minOccurs="0" />
        > </xs:sequence>
        > </xs:complexType>
        > </xs:element>
        > </xs:choice>
        > </xs:complexType>
        > </xs:element>
        > </xs:schema>
        >
        > My .NET code looks like as follows:
        >
        > public function XMLValidattor() as Boolean
        > Dim myXMLDoc As New XmlDocument()
        > Dim myXMLNode As XmlElement
        > Dim myXMLReader As XmlReader
        > Dim sXMLData As String
        >
        > myXMLDoc.Load(S erver.MapPath(" BookSample.xml" ))
        >
        > ' validate xml first
        > Dim TR As New XmlTextReader(N ew StringReader(my XMLDoc.OuterXml ))
        > Dim VR As XmlValidatingRe ader = New XmlValidatingRe ader(TR)
        >
        > VR.Schemas.Add( "urn:Root.x dr", Server.MapPath( "BookSample.xsd "))
        > VR.ValidationTy pe = ValidationType. Schema
        > sErrMsg = ""
        > AddHandler VR.ValidationEv entHandler, AddressOf
        > ValidationCallB ack
        > While VR.Read
        > End While
        > VR.Close()
        > TR.Close()
        > If sErrMsg <> "" Then
        > Return False
        > Else
        > Return True
        > End If
        >
        > Public Sub ValidationCallB ack(ByVal sender As Object, ByVal args As
        > ValidationEvent Args)
        > sErrMsg = args.Message
        > End Sub
        >
        > When I run this I get following error:
        >
        > System.Xml.Sche ma.XmlSchemaExc eption: The attribute targetNamespace does
        > not match the designated namespace URI. An error occurred at
        > file:///c:/inetpub/wwwroot/CMService/BookSample.xsd, (2, 2).
        > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption
        > e, XmlSeverityType severity)
        > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(String code,
        > XmlSchemaObject source)
        > at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
        > targetNamespace , Compositor compositor)
        > at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
        > targetNamespace )
        > at System.Xml.Sche ma.Compiler.Com pile(XmlSchema schema, String
        > targetNamespace , SchemaInfo schemaInfo)
        > at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection
        > collection, XmlNameTable nameTable, SchemaNames schemaNames,
        > ValidationEvent Handler validationEvent Handler, String targetNamespace ,
        > SchemaInfo schemaInfo, Boolean compileContentM odel, XmlResolver
        > resolver)
        > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, SchemaInfo
        > schemaInfo, XmlSchema schema, Boolean compile, XmlResolver resolver)
        > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, XmlReader
        > reader, XmlResolver resolver)
        > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, String uri)
        > at CMService.CMSer vice.XMLReading WithXDR() in
        > C:\Inetpub\wwwr oot\CMService\C MService.asmx.v b:line 674
        >
        >
        > What's wrong now?
        >
        > Thanks in advance.
        >
        > Pratibha
        >
        >
        > *** Sent via Developersdex http://www.developersdex.com ***
        > Don't just participate in USENET...get rewarded for it![/color]


        Comment

        • Dino Chiesa [Microsoft]

          #5
          Re: how to write XDR

          Yes

          and just to be quite clear

          the urn:BookSample. xsd in the VR.Schemas.Add( ) line, must match the
          xmlns:bk="urn:B ookSample.xsd" line in the xml file.

          The "urn:BookSample .xsd" is a XML Namespace, and it could be ANYTHING, even
          something like
          I.love.fried.gr een.tomatoes

          ....as long as it is consistent in the xml doc and in the VR.Schemas.Add( )
          call. What you are doing in the Schemas.Add() call is associating that
          namespace with a particular XSD document (BookSample.xsd , in your case).

          So in fact you could use "urn:Root.x dr" as the namespace, but you would have
          to use it both in the VR.Schemas.Add( ) call as well as in the xml document
          itself eg

          <bk:bookList xmlns:bk="urn:R oot.xdr">

          The presence of the letters "xdr" in the namespace does not mean you are
          actually using XDR as your schema. So using "urn:Root.x dr" as your
          namespace would be a source of potential confusion if you are using XSD.
          In fact the namespace is just a string, and is never evaluated. There is no
          magic anywhere in any compliant XML parser that looks at a namespace like
          "urn:Root.x dr" and interprets it, decides that it might be a filename and
          then tries to find a file by that name. The namespace is treated only as a
          string. It could just as easily be a UUID or (as above)
          "I.love.fried.g reen.tomatoes".

          For more on XML Namespaces please see
          Learn with interactive lessons and technical documentation, earn professional development hours and certifications, and connect with the community.



          -Dino


          "Kirk Allen Evans [MSFT]" <kirke@online.m icrosoft.com> wrote in message
          news:%23DWTaXCP EHA.308@TK2MSFT NGP11.phx.gbl.. .[color=blue]
          > The targetNamespace you have still refers to the XDR schema's namespace.
          >
          > Change this line:
          > VR.Schemas.Add( "urn:Root.x dr", Server.MapPath( "BookSample.xsd "))
          >
          > to this line:
          > VR.Schemas.Add( "urn:BookSample .xsd", Server.MapPath( "BookSample.xsd "))
          >
          >
          > --
          > Kirk Allen Evans
          > http://blogs.msdn.com/kaevans
          >
          > -- This posting is provided "AS IS" with no warranties, and confers no
          > rights.
          >
          > "P A" <dotnet@xml.co. uk> wrote in message
          > news:uAcDpCCPEH A.644@tk2msftng p13.phx.gbl...[color=green]
          > > OK. I am now using XSD. Here is my new xml file.
          > >
          > > <?xml version="1.0"?>
          > > <bk:bookList xmlns:bk="urn:B ookSample.xsd">
          > > <book>
          > > <title>Doe's Book</title>
          > > <author>J Doe</author>
          > > <year>2002</year>
          > > </book>
          > > <book>
          > > <title>Sam's Book</title>
          > > <author>Sam</author>
          > > <year>2003</year>
          > > </book>
          > > </bk:bookList>
          > >
          > > I used XSD.exe to create XSD file. This is what I got
          > >
          > > <?xml version="1.0" encoding="utf-8"?>
          > > <xs:schema id="bookList" targetNamespace ="urn:BookSampl e.xsd"
          > > xmlns:mstns="ur n:BookSample.xs d" xmlns="urn:Book Sample.xsd"
          > > xmlns:xs="http://www.w3.org/2001/XMLSchema"
          > > xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
          > > attributeFormDe fault="qualifie d" elementFormDefa ult="qualified" >
          > > <xs:element name="bookList" msdata:IsDataSe t="true"
          > > msdata:Locale=" en-GB" msdata:Prefix=" bk">
          > > <xs:complexType >
          > > <xs:choice maxOccurs="unbo unded">
          > > <xs:element name="book" form="unqualifi ed">
          > > <xs:complexType >
          > > <xs:sequence>
          > > <xs:element name="title" form="unqualifi ed"
          > > type="xs:string " minOccurs="0" />
          > > <xs:element name="author" form="unqualifi ed"
          > > type="xs:string " minOccurs="0" />
          > > <xs:element name="year" form="unqualifi ed"
          > > type="xs:string " minOccurs="0" />
          > > </xs:sequence>
          > > </xs:complexType>
          > > </xs:element>
          > > </xs:choice>
          > > </xs:complexType>
          > > </xs:element>
          > > </xs:schema>
          > >
          > > My .NET code looks like as follows:
          > >
          > > public function XMLValidattor() as Boolean
          > > Dim myXMLDoc As New XmlDocument()
          > > Dim myXMLNode As XmlElement
          > > Dim myXMLReader As XmlReader
          > > Dim sXMLData As String
          > >
          > > myXMLDoc.Load(S erver.MapPath(" BookSample.xml" ))
          > >
          > > ' validate xml first
          > > Dim TR As New XmlTextReader(N ew StringReader(my XMLDoc.OuterXml ))
          > > Dim VR As XmlValidatingRe ader = New XmlValidatingRe ader(TR)
          > >
          > > VR.Schemas.Add( "urn:Root.x dr", Server.MapPath( "BookSample.xsd "))
          > > VR.ValidationTy pe = ValidationType. Schema
          > > sErrMsg = ""
          > > AddHandler VR.ValidationEv entHandler, AddressOf
          > > ValidationCallB ack
          > > While VR.Read
          > > End While
          > > VR.Close()
          > > TR.Close()
          > > If sErrMsg <> "" Then
          > > Return False
          > > Else
          > > Return True
          > > End If
          > >
          > > Public Sub ValidationCallB ack(ByVal sender As Object, ByVal args As
          > > ValidationEvent Args)
          > > sErrMsg = args.Message
          > > End Sub
          > >
          > > When I run this I get following error:
          > >
          > > System.Xml.Sche ma.XmlSchemaExc eption: The attribute targetNamespace does
          > > not match the designated namespace URI. An error occurred at
          > > file:///c:/inetpub/wwwroot/CMService/BookSample.xsd, (2, 2).
          > > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption
          > > e, XmlSeverityType severity)
          > > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(String code,
          > > XmlSchemaObject source)
          > > at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
          > > targetNamespace , Compositor compositor)
          > > at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
          > > targetNamespace )
          > > at System.Xml.Sche ma.Compiler.Com pile(XmlSchema schema, String
          > > targetNamespace , SchemaInfo schemaInfo)
          > > at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection
          > > collection, XmlNameTable nameTable, SchemaNames schemaNames,
          > > ValidationEvent Handler validationEvent Handler, String targetNamespace ,
          > > SchemaInfo schemaInfo, Boolean compileContentM odel, XmlResolver
          > > resolver)
          > > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, SchemaInfo
          > > schemaInfo, XmlSchema schema, Boolean compile, XmlResolver resolver)
          > > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, XmlReader
          > > reader, XmlResolver resolver)
          > > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, String uri)
          > > at CMService.CMSer vice.XMLReading WithXDR() in
          > > C:\Inetpub\wwwr oot\CMService\C MService.asmx.v b:line 674
          > >
          > >
          > > What's wrong now?
          > >
          > > Thanks in advance.
          > >
          > > Pratibha
          > >
          > >
          > > *** Sent via Developersdex http://www.developersdex.com ***
          > > Don't just participate in USENET...get rewarded for it![/color]
          >
          >[/color]


          Comment

          • PA

            #6
            Re: how to write XDR

            Thank you very much for your replies. I had found out that bug soon
            after posting my message. Thank you for explaining what xmlns actually
            means.

            Another problem.

            I have now modified my XML as follows:

            <?xml version='1.0'?>
            <A:Address xmlns:A="urn:Te st.xsd" xmlns:B="urn:Te st_app1.xsd">
            <Name>My Name</Name>
            <Street>My Street</Street>
            <Country>My Country</Country>
            <B:PostCode>M y Post Code</B:PostCode>
            </A:Address>

            Just added additional xmlns:B for PostCode and reran xsd to create
            XSDs.

            Below are 2 xsds created using xsd.exe

            Test.xsd:
            <?xml version="1.0" encoding="utf-8"?>
            <xs:schema id="NewDataSet " targetNamespace ="urn:Test.x sd"
            xmlns:mstns="ur n:Test.xsd" xmlns="urn:Test .xsd"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
            attributeFormDe fault="qualifie d" elementFormDefa ult="qualified"
            xmlns:app1="urn :Test_app1.xsd" >
            <xs:import namespace="urn: Test_app1.xsd"
            schemaLocation= "Test_app1. xsd" />
            <xs:element name="Address" msdata:Prefix=" A">
            <xs:complexType >
            <xs:sequence>
            <xs:element name="Name" form="unqualifi ed" type="xs:string "
            minOccurs="0" />
            <xs:element name="Street" form="unqualifi ed" type="xs:string "
            minOccurs="0" />
            <xs:element name="Country" form="unqualifi ed" type="xs:string "
            minOccurs="0" />
            <xs:element ref="app1:PostC ode" minOccurs="0" />
            </xs:sequence>
            </xs:complexType>
            </xs:element>
            <xs:element name="NewDataSe t" msdata:IsDataSe t="true"
            msdata:Locale=" en-GB" msdata:Prefix=" A">
            <xs:complexType >
            <xs:choice maxOccurs="unbo unded">
            <xs:element ref="Address" />
            </xs:choice>
            </xs:complexType>
            </xs:element>
            </xs:schema>

            Test_app1.xsd:
            <?xml version="1.0" standalone="yes "?>
            <xs:schema id="NewDataSet " targetNamespace ="urn:Test_app1 .xsd"
            xmlns:mstns="ur n:Test.xsd" xmlns="urn:Test _app1.xsd"
            xmlns:xs="http://www.w3.org/2001/XMLSchema"
            xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
            attributeFormDe fault="qualifie d" elementFormDefa ult="qualified"
            xmlns:app1="urn :Test_app1.xsd" >
            <xs:import namespace="urn: Test.xsd" schemaLocation= "Test.xsd" />
            <xs:element name="PostCode" msdata:Prefix=" B" type="xs:string " />
            </xs:schema>

            I have also modified my code to add both schemas in schema cache:

            VR.Schemas.Add( "urn:Test.x sd", Server.MapPath( "Test.xsd") )
            VR.Schemas.Add( "urn:Test_app1. xsd", Server.MapPath( "Test_app1.xsd" ))

            When I run my code, I get following error:
            System.Xml.Sche ma.XmlSchemaExc eption: The global element
            'urn:Test_app1. xsd:PostCode' has already been declared. An error
            occurred at file:///c:/inetpub/wwwroot/CMService/Test_app1.xsd, (4,
            4).
            at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption
            e, XmlSeverityType severity)
            at System.Xml.Sche ma.Compiler.Sen dValidationEven t(String code,
            String msg, XmlSchemaObject source)
            at System.Xml.Sche ma.Compiler.Add ToTable(XmlSche maObjectTable
            table, XmlQualifiedNam e qname, XmlSchemaObject item)
            at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
            targetNamespace , Compositor compositor)
            at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
            targetNamespace )
            at System.Xml.Sche ma.Compiler.Com pile(XmlSchema schema, String
            targetNamespace , SchemaInfo schemaInfo)
            at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection
            collection, XmlNameTable nameTable, SchemaNames schemaNames,
            ValidationEvent Handler validationEvent Handler, String targetNamespace ,
            SchemaInfo schemaInfo, Boolean compileContentM odel, XmlResolver
            resolver)
            at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, SchemaInfo
            schemaInfo, XmlSchema schema, Boolean compile, XmlResolver resolver)
            at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, XmlReader
            reader, XmlResolver resolver)
            at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, String uri)
            at CMService.CMSer vice.XMLReading WithXDR() in
            C:\Inetpub\wwwr oot\CMService\C MService.asmx.v b:line 675

            What's wrong now?

            Thanks in advance.

            Pratibha

            Comment

            • Dino Chiesa [Microsoft]

              #7
              Re: how to write XDR

              maybe the Test_app1.xsd has already been recurseively added by the original
              Add();

              "PA" <pratibhaa@jvc. co.uk> wrote in message
              news:f7b9f4bb.0 405180038.5b2f2 e6d@posting.goo gle.com...[color=blue]
              > Thank you very much for your replies. I had found out that bug soon
              > after posting my message. Thank you for explaining what xmlns actually
              > means.
              >
              > Another problem.
              >
              > I have now modified my XML as follows:
              >
              > <?xml version='1.0'?>
              > <A:Address xmlns:A="urn:Te st.xsd" xmlns:B="urn:Te st_app1.xsd">
              > <Name>My Name</Name>
              > <Street>My Street</Street>
              > <Country>My Country</Country>
              > <B:PostCode>M y Post Code</B:PostCode>
              > </A:Address>
              >
              > Just added additional xmlns:B for PostCode and reran xsd to create
              > XSDs.
              >
              > Below are 2 xsds created using xsd.exe
              >
              > Test.xsd:
              > <?xml version="1.0" encoding="utf-8"?>
              > <xs:schema id="NewDataSet " targetNamespace ="urn:Test.x sd"
              > xmlns:mstns="ur n:Test.xsd" xmlns="urn:Test .xsd"
              > xmlns:xs="http://www.w3.org/2001/XMLSchema"
              > xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
              > attributeFormDe fault="qualifie d" elementFormDefa ult="qualified"
              > xmlns:app1="urn :Test_app1.xsd" >
              > <xs:import namespace="urn: Test_app1.xsd"
              > schemaLocation= "Test_app1. xsd" />
              > <xs:element name="Address" msdata:Prefix=" A">
              > <xs:complexType >
              > <xs:sequence>
              > <xs:element name="Name" form="unqualifi ed" type="xs:string "
              > minOccurs="0" />
              > <xs:element name="Street" form="unqualifi ed" type="xs:string "
              > minOccurs="0" />
              > <xs:element name="Country" form="unqualifi ed" type="xs:string "
              > minOccurs="0" />
              > <xs:element ref="app1:PostC ode" minOccurs="0" />
              > </xs:sequence>
              > </xs:complexType>
              > </xs:element>
              > <xs:element name="NewDataSe t" msdata:IsDataSe t="true"
              > msdata:Locale=" en-GB" msdata:Prefix=" A">
              > <xs:complexType >
              > <xs:choice maxOccurs="unbo unded">
              > <xs:element ref="Address" />
              > </xs:choice>
              > </xs:complexType>
              > </xs:element>
              > </xs:schema>
              >
              > Test_app1.xsd:
              > <?xml version="1.0" standalone="yes "?>
              > <xs:schema id="NewDataSet " targetNamespace ="urn:Test_app1 .xsd"
              > xmlns:mstns="ur n:Test.xsd" xmlns="urn:Test _app1.xsd"
              > xmlns:xs="http://www.w3.org/2001/XMLSchema"
              > xmlns:msdata="u rn:schemas-microsoft-com:xml-msdata"
              > attributeFormDe fault="qualifie d" elementFormDefa ult="qualified"
              > xmlns:app1="urn :Test_app1.xsd" >
              > <xs:import namespace="urn: Test.xsd" schemaLocation= "Test.xsd" />
              > <xs:element name="PostCode" msdata:Prefix=" B" type="xs:string " />
              > </xs:schema>
              >
              > I have also modified my code to add both schemas in schema cache:
              >
              > VR.Schemas.Add( "urn:Test.x sd", Server.MapPath( "Test.xsd") )
              > VR.Schemas.Add( "urn:Test_app1. xsd", Server.MapPath( "Test_app1.xsd" ))
              >
              > When I run my code, I get following error:
              > System.Xml.Sche ma.XmlSchemaExc eption: The global element
              > 'urn:Test_app1. xsd:PostCode' has already been declared. An error
              > occurred at file:///c:/inetpub/wwwroot/CMService/Test_app1.xsd, (4,
              > 4).
              > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(XmlSchemaExce ption
              > e, XmlSeverityType severity)
              > at System.Xml.Sche ma.Compiler.Sen dValidationEven t(String code,
              > String msg, XmlSchemaObject source)
              > at System.Xml.Sche ma.Compiler.Add ToTable(XmlSche maObjectTable
              > table, XmlQualifiedNam e qname, XmlSchemaObject item)
              > at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
              > targetNamespace , Compositor compositor)
              > at System.Xml.Sche ma.Compiler.Pre process(XmlSche ma schema, String
              > targetNamespace )
              > at System.Xml.Sche ma.Compiler.Com pile(XmlSchema schema, String
              > targetNamespace , SchemaInfo schemaInfo)
              > at System.Xml.Sche ma.XmlSchema.Co mpile(XmlSchema Collection
              > collection, XmlNameTable nameTable, SchemaNames schemaNames,
              > ValidationEvent Handler validationEvent Handler, String targetNamespace ,
              > SchemaInfo schemaInfo, Boolean compileContentM odel, XmlResolver
              > resolver)
              > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, SchemaInfo
              > schemaInfo, XmlSchema schema, Boolean compile, XmlResolver resolver)
              > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, XmlReader
              > reader, XmlResolver resolver)
              > at System.Xml.Sche ma.XmlSchemaCol lection.Add(Str ing ns, String uri)
              > at CMService.CMSer vice.XMLReading WithXDR() in
              > C:\Inetpub\wwwr oot\CMService\C MService.asmx.v b:line 675
              >
              > What's wrong now?
              >
              > Thanks in advance.
              >
              > Pratibha[/color]


              Comment

              Working...