XML Validation: required attributes

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

    XML Validation: required attributes

    Hello All,
    I was trying to validate an XML document against a XSD which works
    fine. Then I tried to put in a version attribute on the root element and
    set it to a fixed value of '1.0' in the schema. Guess what? The
    validator completely ignores the attribute inspite of the fact that I
    have set the attribute to be required and to have a fixed value of '1.0'.
    Any ideas why that could be happening. Any help is appreciated.
    Uttara
  • Stan Kitsis [MSFT]

    #2
    Re: XML Validation: required attributes

    Either you didn't do what you thought you did or the validator has a
    problem. Which validator did you use and what are your schema/instance?

    --
    Stan Kitsis
    Program Manager, XML Technologies
    Microsoft Corporation

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


    "uttara" <planetu99@hotm ail.com> wrote in message
    news:OQyYU5nBGH A.1028@TK2MSFTN GP11.phx.gbl...[color=blue]
    > Hello All,
    > I was trying to validate an XML document against a XSD which works fine.
    > Then I tried to put in a version attribute on the root element and set it
    > to a fixed value of '1.0' in the schema. Guess what? The validator
    > completely ignores the attribute inspite of the fact that I have set the
    > attribute to be required and to have a fixed value of '1.0'.
    > Any ideas why that could be happening. Any help is appreciated.
    > Uttara[/color]


    Comment

    • uttara

      #3
      Re: XML Validation: required attributes

      Stan,
      I won't be utterly surprised if I missed out something. I am using the
      XMLValidatingRe ader. Here is the schema I am using:
      <?xml version="1.0" encoding="utf-8"?>
      <xs:schema id="Schema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="Products" >
      <xs:complexType >
      <xs:sequence>
      <xs:element name="ItemCode" minOccurs="1"
      maxOccurs="unbo unded">
      <xs:complexType >
      <xs:sequence>
      <xs:element name="SKU" type="xs:string "
      minOccurs="0" maxOccurs="unbo unded" />
      </xs:sequence>
      <xs:attribute name="code" type="xs:string " />
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      <xs:attribute name="schemaVer sion" type="xs:decima l"
      use="required" fixed="1.0" />
      </xs:complexType>
      </xs:element>
      </xs:schema>

      Here is the instance
      <?xml version="1.0" encoding="utf-8" ?>
      <Products schemaVersion=" 1.1">
      <ItemCode code="10098"></ItemCode>
      <ItemCode code="10047">
      <SKU>0023</SKU>
      <SKU>0025</SKU>
      </ItemCode>
      </Products>

      Thanks again,
      Uttara

      Stan Kitsis [MSFT] wrote:[color=blue]
      > Either you didn't do what you thought you did or the validator has a
      > problem. Which validator did you use and what are your schema/instance?
      >[/color]

      Comment

      • Stan Kitsis [MSFT]

        #4
        Re: XML Validation: required attributes

        I get the following warning using .net 2.0: "The value of the
        'schemaVersion' attribute does not equal its fixed value."

        --
        Stan Kitsis
        Program Manager, XML Technologies
        Microsoft Corporation

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


        "uttara" <planetu99@hotm ail.com> wrote in message
        news:e1cn4kyBGH A.3580@TK2MSFTN GP11.phx.gbl...[color=blue]
        > Stan,
        > I won't be utterly surprised if I missed out something. I am using the
        > XMLValidatingRe ader. Here is the schema I am using:
        > <?xml version="1.0" encoding="utf-8"?>
        > <xs:schema id="Schema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        > <xs:element name="Products" >
        > <xs:complexType >
        > <xs:sequence>
        > <xs:element name="ItemCode" minOccurs="1"
        > maxOccurs="unbo unded">
        > <xs:complexType >
        > <xs:sequence>
        > <xs:element name="SKU" type="xs:string "
        > minOccurs="0" maxOccurs="unbo unded" />
        > </xs:sequence>
        > <xs:attribute name="code" type="xs:string " />
        > </xs:complexType>
        > </xs:element>
        > </xs:sequence>
        > <xs:attribute name="schemaVer sion" type="xs:decima l"
        > use="required" fixed="1.0" />
        > </xs:complexType>
        > </xs:element>
        > </xs:schema>
        >
        > Here is the instance
        > <?xml version="1.0" encoding="utf-8" ?>
        > <Products schemaVersion=" 1.1">
        > <ItemCode code="10098"></ItemCode>
        > <ItemCode code="10047">
        > <SKU>0023</SKU>
        > <SKU>0025</SKU>
        > </ItemCode>
        > </Products>
        >
        > Thanks again,
        > Uttara
        >
        > Stan Kitsis [MSFT] wrote:[color=green]
        >> Either you didn't do what you thought you did or the validator has a
        >> problem. Which validator did you use and what are your schema/instance?
        >>[/color][/color]


        Comment

        • uttara

          #5
          Re: XML Validation: required attributes

          Hmm...what if we take out the schemaVersion attribute from the root
          element so it looks like this:
          <?xml version="1.0" encoding="utf-8" ?>[color=blue]
          > <Products>
          > <ItemCode code="10098"></ItemCode>
          > <ItemCode code="10047">
          > <SKU>0023</SKU>
          > <SKU>0025</SKU>
          > </ItemCode>
          > </Products>[/color]

          Stan Kitsis [MSFT] wrote:[color=blue]
          > I get the following warning using .net 2.0: "The value of the
          > 'schemaVersion' attribute does not equal its fixed value."
          >[/color]

          Comment

          • Stan Kitsis [MSFT]

            #6
            Re: XML Validation: required attributes

            This should be invalid since the version attribute is required.

            --
            Stan Kitsis
            Program Manager, XML Technologies
            Microsoft Corporation

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

            "uttara" <planetu99@hotm ail.com> wrote in message
            news:uQuVy8zBGH A.3064@TK2MSFTN GP10.phx.gbl...[color=blue]
            > Hmm...what if we take out the schemaVersion attribute from the root
            > element so it looks like this:
            > <?xml version="1.0" encoding="utf-8" ?>[color=green]
            > > <Products>
            > > <ItemCode code="10098"></ItemCode>
            > > <ItemCode code="10047">
            > > <SKU>0023</SKU>
            > > <SKU>0025</SKU>
            > > </ItemCode>
            > > </Products>[/color]
            >
            > Stan Kitsis [MSFT] wrote:[color=green]
            >> I get the following warning using .net 2.0: "The value of the
            >> 'schemaVersion' attribute does not equal its fixed value."
            >>[/color][/color]


            Comment

            • Chris Lovett

              #7
              Re: XML Validation: required attributes

              The following code does produce the warning:
              "The value of the 'schemaVersion' attribute does not equal its fixed
              value."


              static void Main(string[] args) {
              Directory.SetCu rrentDirectory( "..\\..");

              ValidationEvent Handler handler = new
              ValidationEvent Handler(OnValid ationEvent);
              XmlTextReader reader = new XmlTextReader(" test.xml");
              XmlValidatingRe ader validator = new XmlValidatingRe ader(reader);
              validator.Schem as.Add(XmlSchem a.Read(new
              StreamReader("t est.xsd"), handler));
              validator.Valid ationType = ValidationType. Schema;
              validator.Valid ationEventHandl er += handler;
              while (validator.Read ()) {
              }
              return;
              }

              static void OnValidationEve nt(object sender, ValidationEvent Args e)
              {
              Console.WriteLi ne(e.Message);
              }



              "uttara" <planetu99@hotm ail.com> wrote in message
              news:e1cn4kyBGH A.3580@TK2MSFTN GP11.phx.gbl...[color=blue]
              > Stan,
              > I won't be utterly surprised if I missed out something. I am using the
              > XMLValidatingRe ader. Here is the schema I am using:
              > <?xml version="1.0" encoding="utf-8"?>
              > <xs:schema id="Schema" xmlns:xs="http://www.w3.org/2001/XMLSchema">
              > <xs:element name="Products" >
              > <xs:complexType >
              > <xs:sequence>
              > <xs:element name="ItemCode" minOccurs="1"
              > maxOccurs="unbo unded">
              > <xs:complexType >
              > <xs:sequence>
              > <xs:element name="SKU" type="xs:string "
              > minOccurs="0" maxOccurs="unbo unded" />
              > </xs:sequence>
              > <xs:attribute name="code" type="xs:string " />
              > </xs:complexType>
              > </xs:element>
              > </xs:sequence>
              > <xs:attribute name="schemaVer sion" type="xs:decima l"
              > use="required" fixed="1.0" />
              > </xs:complexType>
              > </xs:element>
              > </xs:schema>
              >
              > Here is the instance
              > <?xml version="1.0" encoding="utf-8" ?>
              > <Products schemaVersion=" 1.1">
              > <ItemCode code="10098"></ItemCode>
              > <ItemCode code="10047">
              > <SKU>0023</SKU>
              > <SKU>0025</SKU>
              > </ItemCode>
              > </Products>
              >
              > Thanks again,
              > Uttara
              >
              > Stan Kitsis [MSFT] wrote:[color=green]
              >> Either you didn't do what you thought you did or the validator has a
              >> problem. Which validator did you use and what are your schema/instance?
              >>[/color][/color]


              Comment

              Working...