Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1441

QNameDatatypeValidator does not resolve namespaces when making comparisions

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.6.0
    • 3.0.0
    • None
    • Linux 2.4.21-27 i686 GNU/Linux
      gcc (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-49)

    Description

      Xerces-C can not properly validate enumerations with a QName base.It will validate only if the enumeration's QName's prefix is exactly the same as the namespace prefix defined in the XSD.

      For example, the schema is defined as:
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:tns="http://www.example.com/qname"
      xmlns:xml="http://www.w3.org/XML/1998/namespace"
      targetNamespace="http://www.example.com/qname"
      elementFormDefault="qualified" > ...
      (the full schema is included below)

      Then the XML document will validate (using same namespace prefix):

      <tns:Body xmlns:tns="http://www.example.com/qname"
      xmlns:xml="http://www.w3.org/XML/1998/namespace">
      <tns:Fault>
      <tns:Code>
      <tns:Value>tns:Sender</tns:Value>
      </tns:Code>
      </tns:Fault>
      </tns:Body>

      But the following will not (using a different namespace prefix):

      <my-tns:Body xmlns:my-tns="http://www.example.com/qname"
      xmlns:xml="http://www.w3.org/XML/1998/namespace">
      <my-tns:Fault>
      <my-tns:Code>
      <my-tns:Value>my-tns:Sender</my-tns:Value>
      </my-tns:Code>
      </my-tns:Fault>
      </my-tns:Body>

      I have tracked the root of this problem down to trunk/src/xercesc/validators/datatype/QNameDatatypeValidator.cpp line 185:

      for ( ; i < enumLength; i++)

      { if (XMLString::equals(normContent, getEnumeration()->elementAt(i))) break; }

      if (i == enumLength)
      ThrowXMLwithMemMgr1(InvalidDatatypeValueException, XMLExcepts::VALUE_NotIn_Enumeration, content, manager);

      The comparison XMLString::equals is comparing the QName string with the URI prefix (i.e. tns:Sender) instead of the the URI itself (i.e.

      {http://www.example.com/qname}

      :Sender). So if the XML uses a different namespace prefix than that of the schema definition, it will fail.

      Attachments

        1. QnameTest.cpp
          3 kB
          Alex Dickinson
        2. qname-good.xml
          0.3 kB
          Alex Dickinson
        3. qname-bad.xml
          0.3 kB
          Alex Dickinson
        4. qname.xsd
          1 kB
          Alex Dickinson

        Activity

          People

            cargilld@ca.ibm.com cargilld
            sideshowalex Alex Dickinson
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: