Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Known Issues in System.Xml

This section describes known issues in the System.Xml implementation.

There are differences between XSLT compiled in Debug mode and XSLT compiled in Release mode. In some situations, style sheets compiled in Debug mode will not throw errors during Load, but will later fail during Transform. The same style sheet compiled in Release mode will fail during Load.

An example of such behavior is when a variable that is not of a node-set type is assigned to an expression where a node-set is required.

The System.Xml implementation of the World Wide Web Consortium (W3C) Recommendations for XML Schemas uses the RegEx class to perform pattern matching of regular expressions. In some cases, the behavior recommended by W3C differs from the RegEx class behavior. The following are the known cases where the System.Xml implementation of pattern matching differs from the W3C specification:

  • According to the W3C for XML Schema specification, the dollar sign ($) should be treated as a regular character. However, the System.Xml validation interprets a dollar sign in the xs:pattern as an end-of-line anchor. The possible workaround is to replace $ with [$]. If your pattern is already in brackets, such as [abc$], it is not necessary to make any changes.

  • The RegEx class follows the definition of \p{C} from the Unicode Standard. The Unicode Standard defines general category C as Cc | Cf | Cn | Co | Cs, where the Cs category identifies surrogate characters. Because surrogate characters do not occur at the level of character abstraction that XML instance documents use, the W3C changes the definition of \p{C} by removing the Cs property from the group. To avoid XML validation errors, change \p{C} in the xs:pattern to \p{Cc}|\p{Cf}|\p{Co}|\p{Cn} literal string.

The World Wide Web Consortium (W3C) Recommendations for XML Schemas specifies that the xs:time data type should accept the value 24:00:00 as valid, and that 24:00:00 specifies the first instance of the next day.

The System.Xml implementation does not accept the value 24:00:00 as valid. If you assign 24:00:00 to an element of the xs:time type, a validation error will occur.

In some cases, when substitution groups are used, the System.Xml implementation does not satisfy the Schema Component Constraint: Element Declarations Consistent, which is described in the Constraints on Model Group Schema Components section of the W3C spec.

For example, in the following schema there are elements of the same name and different types in the same content model, and substitution groups are used. This should cause an error, but System.Xml compiles and validates the schema without errors.

<?xml version="1.0" encoding="utf-8" ?> 
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

   <xs:element name="e1" type="t1"/>
   <xs:complexType name="t1"/>

   <xs:element name="e2" type="t2" substitutionGroup="e1"/>
      <xs:complexType name="t2">
         <xs:complexContent>
            <xs:extension base="t1">
         </xs:extension>
      </xs:complexContent>
   </xs:complexType>

   <xs:complexType name="t3">
      <xs:sequence>
         <xs:element ref="e1"/>
         <xs:element name="e2" type="xs:int"/>
      </xs:sequence>
   </xs:complexType>
</xs:schema>

In this schema, type t3 contains a sequence of elements. Because of the substitution, the reference to element e1 from the sequence can result either in element e1 of type t1 or in element e2 of type t2. In the latter case, this would result in a sequence of two e2 elements where the first e2 element is of type t2 while the second e2 element is of type xs:int.

Under all of the following conditions, the System.Xml implementation does not satisfy the Schema Component Constraint: Unique Particle Attribution of the W3C specification.

  • One of the elements in the group references another element.

  • The referenced element is a head element of a substitution group.

  • In the substitution group there is an element that has the same name as one of the elements in the group.

  • The cardinality of the element referencing the substitution group head element and the element with the same name as one of elements from the substitution group is not fixed (minOccurs < maxOccurs).

  • The definition of the element referencing the substitution group precedes the definition of the element with the same name as one of elements from the substitution group.

For example, in the schema below the content model is ambiguous and should cause a compilation error, but System.Xml compiles the schema without errors.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

  <xs:element name="e1" type="xs:int"/>
  <xs:element name="e2" type="xs:int" substitutionGroup="e1"/>

  <xs:complexType name="t3">
    <xs:sequence>
      <xs:element ref="e1" minOccurs="0" maxOccurs="1"/>
      <xs:element name="e2" type="xs:int" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>
  </xs:complexType>
  
  <xs:element name="e3" type="t3"/>
</xs:schema>

If you try to validate the following XML against the schema above, the validation will fail with the following message: "The element 'e3' has invalid child element 'e2'." XmlSchemaValidationException.

<e3>

<e2>1</e2>

<e2>2</e2>

</e3>

The possible workaround is to swap element declarations in the XSD document. For example, this:

    <xs:sequence>
      <xs:element ref="e1" minOccurs="0" maxOccurs="1"/>
      <xs:element name="e2" type="xs:int" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>

becomes this:

    <xs:sequence>
      <xs:element name="e2" type="xs:int" minOccurs="0" maxOccurs="1"/>
      <xs:element ref="e1" minOccurs="0" maxOccurs="1"/>
    </xs:sequence>

Another example of the same issue is demonstrated in the following schema.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
   <xs:element name="e1" type="xs:string"/>
   <xs:element name="e2" type="xs:string" substitutionGroup="e1"/>
   
   <xs:complexType name="t3">
      <xs:sequence>
         <xs:element ref="e1" minOccurs="0" maxOccurs="1"/>
         <xs:element name="e2" type="xs:int" minOccurs="0" maxOccurs="1"/>
      </xs:sequence>
   </xs:complexType>
   <xs:element name="e3" type="t3"/>
</xs:schema>

If you try to validate the following XML against the schema above, the validation will fail with the following exception: "Unhandled Exception: System.Xml.Schema.XmlSchemaValidationException: The 'e2' el element is invalid - The value 'abc' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:int' - The string 'abc' is not a valid Int32 value. --"\

<e3><e2>abc</e2></e3>
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.