.Net XmlValidatingReader should fail on complextypes with whitespace?

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

    .Net XmlValidatingReader should fail on complextypes with whitespace?

    I believe the .Net XmlValidatingRe ader should fail when validating XML
    that contains a ComplexType element with white space when the
    ComplexType element has the mixed attribute set to false in the XSD used
    for validation.

    XSD fragment:

    <xs:element name="TRSellerB uyerData">
    <xs:complexTy pe mixed="false">
    <xs:sequence>
    <xs:element ref="BuyerSelle rReferrorFlag" minOccurs="0"
    maxOccurs="unbo unded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    XML fragment:

    <TRSellerBuyerD ata>
    </TRSellerBuyerDa ta>

    XML Spy will catch the valdation error and report: "Text not allowed
    inside element 'TRSellerBuyerD ata'

    But the following code does not catch the validation error. Is this a
    bug in XmlValidatingRe ader - or am I missing code to catch this? I
    assume by XSD is correct since XmlSpy catches the error.


    XmlTextReader textReader = new XmlTextReader(r eader);

    textReader.Whit espaceHandling = WhitespaceHandl ing.All; //this is the
    default

    textReader.Norm alization = false; //this is the default

    XmlValidatingRe ader validatingReade r = new XmlValidatingRe ader(textReader );

    validatingReade r.ValidationTyp e = ValidationType. Schema;

    validatingReade r.Schemas.Add(s chemaCollection );

    try
    {
    while(validatin gReader.Read()) ;
    }
    catch(Exception ex)
    {
    Debug.WriteLine (ex.Message);
    }


    -Larry
  • Priya Lakshminarayanan [MSFT]

    #2
    Re: .Net XmlValidatingRe ader should fail on complextypes with whitespace?

    The following complexType's ContentType is ElementOnly according to
    structures spec. (http://www.w3.org/TR/xmlschema-1)
    and if the ContentType is ElementOnly, then whitespace characters are
    allowed according to clause 2.3 of the following rule in the spec:
    3.4.4 Complex Type Definition Validation Rules
    Validation Rule: Element Locally Valid (Complex Type)
    2.3 If the {content type} is element-only, then the element information item
    has no character information item [children] other than those whose
    [character code] is defined as a white space in [XML 1.0 (Second Edition)].

    Thanks,
    Priya


    "Larry" <larry@nospam.n et> wrote in message
    news:z_Vvc.343$ 4S5.259@attbi_s 52...[color=blue]
    > I believe the .Net XmlValidatingRe ader should fail when validating XML
    > that contains a ComplexType element with white space when the
    > ComplexType element has the mixed attribute set to false in the XSD used
    > for validation.
    >
    > XSD fragment:
    >
    > <xs:element name="TRSellerB uyerData">
    > <xs:complexTy pe mixed="false">
    > <xs:sequence>
    > <xs:element ref="BuyerSelle rReferrorFlag" minOccurs="0"
    > maxOccurs="unbo unded"/>
    > </xs:sequence>
    > </xs:complexType>
    > </xs:element>
    >
    > XML fragment:
    >
    > <TRSellerBuyerD ata>
    > </TRSellerBuyerDa ta>
    >
    > XML Spy will catch the valdation error and report: "Text not allowed
    > inside element 'TRSellerBuyerD ata'
    >
    > But the following code does not catch the validation error. Is this a
    > bug in XmlValidatingRe ader - or am I missing code to catch this? I
    > assume by XSD is correct since XmlSpy catches the error.
    >
    >
    > XmlTextReader textReader = new XmlTextReader(r eader);
    >
    > textReader.Whit espaceHandling = WhitespaceHandl ing.All; //this is the
    > default
    >
    > textReader.Norm alization = false; //this is the default
    >
    > XmlValidatingRe ader validatingReade r = new[/color]
    XmlValidatingRe ader(textReader );[color=blue]
    >
    > validatingReade r.ValidationTyp e = ValidationType. Schema;
    >
    > validatingReade r.Schemas.Add(s chemaCollection );
    >
    > try
    > {
    > while(validatin gReader.Read()) ;
    > }
    > catch(Exception ex)
    > {
    > Debug.WriteLine (ex.Message);
    > }
    >
    >
    > -Larry[/color]


    Comment

    • Priya Lakshminarayanan [MSFT]

      #3
      Re: .Net XmlValidatingRe ader should fail on complextypes with whitespace?

      The following complexType's ContentType is ElementOnly according to
      structures spec. (http://www.w3.org/TR/xmlschema-1)
      and if the ContentType is ElementOnly, then whitespace characters are
      allowed according to clause 2.3 of the following rule in the spec:
      3.4.4 Complex Type Definition Validation Rules
      Validation Rule: Element Locally Valid (Complex Type)
      2.3 If the {content type} is element-only, then the element information item
      has no character information item [children] other than those whose
      [character code] is defined as a white space in [XML 1.0 (Second Edition)].

      Thanks,
      Priya


      "Larry" <larry@nospam.n et> wrote in message
      news:z_Vvc.343$ 4S5.259@attbi_s 52...[color=blue]
      > I believe the .Net XmlValidatingRe ader should fail when validating XML
      > that contains a ComplexType element with white space when the
      > ComplexType element has the mixed attribute set to false in the XSD used
      > for validation.
      >
      > XSD fragment:
      >
      > <xs:element name="TRSellerB uyerData">
      > <xs:complexTy pe mixed="false">
      > <xs:sequence>
      > <xs:element ref="BuyerSelle rReferrorFlag" minOccurs="0"
      > maxOccurs="unbo unded"/>
      > </xs:sequence>
      > </xs:complexType>
      > </xs:element>
      >
      > XML fragment:
      >
      > <TRSellerBuyerD ata>
      > </TRSellerBuyerDa ta>
      >
      > XML Spy will catch the valdation error and report: "Text not allowed
      > inside element 'TRSellerBuyerD ata'
      >
      > But the following code does not catch the validation error. Is this a
      > bug in XmlValidatingRe ader - or am I missing code to catch this? I
      > assume by XSD is correct since XmlSpy catches the error.
      >
      >
      > XmlTextReader textReader = new XmlTextReader(r eader);
      >
      > textReader.Whit espaceHandling = WhitespaceHandl ing.All; //this is the
      > default
      >
      > textReader.Norm alization = false; //this is the default
      >
      > XmlValidatingRe ader validatingReade r = new[/color]
      XmlValidatingRe ader(textReader );[color=blue]
      >
      > validatingReade r.ValidationTyp e = ValidationType. Schema;
      >
      > validatingReade r.Schemas.Add(s chemaCollection );
      >
      > try
      > {
      > while(validatin gReader.Read()) ;
      > }
      > catch(Exception ex)
      > {
      > Debug.WriteLine (ex.Message);
      > }
      >
      >
      > -Larry[/color]


      Comment

      • Larry

        #4
        Re: .Net XmlValidatingRe ader should fail on complextypes with whitespace?

        Thank you Priya, how would I change my XSD so that only child elements
        are allowed and no "significan t" white space?

        Priya Lakshminarayana n [MSFT] wrote:[color=blue]
        > The following complexType's ContentType is ElementOnly according to
        > structures spec. (http://www.w3.org/TR/xmlschema-1)
        > and if the ContentType is ElementOnly, then whitespace characters are
        > allowed according to clause 2.3 of the following rule in the spec:
        > 3.4.4 Complex Type Definition Validation Rules
        > Validation Rule: Element Locally Valid (Complex Type)
        > 2.3 If the {content type} is element-only, then the element information item
        > has no character information item [children] other than those whose
        > [character code] is defined as a white space in [XML 1.0 (Second Edition)].
        >
        > Thanks,
        > Priya
        >
        >
        > "Larry" <larry@nospam.n et> wrote in message
        > news:z_Vvc.343$ 4S5.259@attbi_s 52...
        >[color=green]
        >>I believe the .Net XmlValidatingRe ader should fail when validating XML
        >>that contains a ComplexType element with white space when the
        >>ComplexType element has the mixed attribute set to false in the XSD used
        >>for validation.
        >>
        >>XSD fragment:
        >>
        >><xs:element name="TRSellerB uyerData">
        >><xs:complexTy pe mixed="false">
        >><xs:sequenc e>
        >><xs:element ref="BuyerSelle rReferrorFlag" minOccurs="0"
        >>maxOccurs="un bounded"/>
        >></xs:sequence>
        >></xs:complexType>
        >></xs:element>
        >>
        >>XML fragment:
        >>
        >><TRSellerBuye rData>
        >></TRSellerBuyerDa ta>
        >>
        >>XML Spy will catch the valdation error and report: "Text not allowed
        >>inside element 'TRSellerBuyerD ata'
        >>
        >>But the following code does not catch the validation error. Is this a
        >>bug in XmlValidatingRe ader - or am I missing code to catch this? I
        >>assume by XSD is correct since XmlSpy catches the error.
        >>
        >>
        >>XmlTextRead er textReader = new XmlTextReader(r eader);
        >>
        >>textReader.Wh itespaceHandlin g = WhitespaceHandl ing.All; //this is the
        >>default
        >>
        >>textReader.No rmalization = false; //this is the default
        >>
        >>XmlValidating Reader validatingReade r = new[/color]
        >
        > XmlValidatingRe ader(textReader );
        >[color=green]
        >>validatingRea der.ValidationT ype = ValidationType. Schema;
        >>
        >>validatingRea der.Schemas.Add (schemaCollecti on);
        >>
        >>try
        >>{
        >>while(validat ingReader.Read( ));
        >>}
        >>catch(Excepti on ex)
        >>{
        >>Debug.WriteLi ne(ex.Message);
        >>}
        >>
        >>
        >>-Larry[/color]
        >
        >
        >[/color]

        Comment

        • Larry

          #5
          Re: .Net XmlValidatingRe ader should fail on complextypes with whitespace?

          Thank you Priya, how would I change my XSD so that only child elements
          are allowed and no "significan t" white space?

          Priya Lakshminarayana n [MSFT] wrote:[color=blue]
          > The following complexType's ContentType is ElementOnly according to
          > structures spec. (http://www.w3.org/TR/xmlschema-1)
          > and if the ContentType is ElementOnly, then whitespace characters are
          > allowed according to clause 2.3 of the following rule in the spec:
          > 3.4.4 Complex Type Definition Validation Rules
          > Validation Rule: Element Locally Valid (Complex Type)
          > 2.3 If the {content type} is element-only, then the element information item
          > has no character information item [children] other than those whose
          > [character code] is defined as a white space in [XML 1.0 (Second Edition)].
          >
          > Thanks,
          > Priya
          >
          >
          > "Larry" <larry@nospam.n et> wrote in message
          > news:z_Vvc.343$ 4S5.259@attbi_s 52...
          >[color=green]
          >>I believe the .Net XmlValidatingRe ader should fail when validating XML
          >>that contains a ComplexType element with white space when the
          >>ComplexType element has the mixed attribute set to false in the XSD used
          >>for validation.
          >>
          >>XSD fragment:
          >>
          >><xs:element name="TRSellerB uyerData">
          >><xs:complexTy pe mixed="false">
          >><xs:sequenc e>
          >><xs:element ref="BuyerSelle rReferrorFlag" minOccurs="0"
          >>maxOccurs="un bounded"/>
          >></xs:sequence>
          >></xs:complexType>
          >></xs:element>
          >>
          >>XML fragment:
          >>
          >><TRSellerBuye rData>
          >></TRSellerBuyerDa ta>
          >>
          >>XML Spy will catch the valdation error and report: "Text not allowed
          >>inside element 'TRSellerBuyerD ata'
          >>
          >>But the following code does not catch the validation error. Is this a
          >>bug in XmlValidatingRe ader - or am I missing code to catch this? I
          >>assume by XSD is correct since XmlSpy catches the error.
          >>
          >>
          >>XmlTextRead er textReader = new XmlTextReader(r eader);
          >>
          >>textReader.Wh itespaceHandlin g = WhitespaceHandl ing.All; //this is the
          >>default
          >>
          >>textReader.No rmalization = false; //this is the default
          >>
          >>XmlValidating Reader validatingReade r = new[/color]
          >
          > XmlValidatingRe ader(textReader );
          >[color=green]
          >>validatingRea der.ValidationT ype = ValidationType. Schema;
          >>
          >>validatingRea der.Schemas.Add (schemaCollecti on);
          >>
          >>try
          >>{
          >>while(validat ingReader.Read( ));
          >>}
          >>catch(Excepti on ex)
          >>{
          >>Debug.WriteLi ne(ex.Message);
          >>}
          >>
          >>
          >>-Larry[/color]
          >
          >
          >[/color]

          Comment

          Working...