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

xml:lang attribute is not validated

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.5.0
    • Fix Version/s: 2.6.0
    • Labels:
      None
    • Environment:
      Windows XP, Visual C++ 6

      Description

      Given this XSD

      <?xml version="1.0"?>
      <xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <!-Import for xml:lang and xml:space->
      <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>

      <xs:element name="root">
      <xs:complexType>
      <xs:sequence>
      <xs:element name="tag" type="xs:string"/>
      </xs:sequence>
      <xs:attribute name="attr" type="xs:string" use="required"/>
      <xs:attribute ref="xml:lang" use="required"/>
      </xs:complexType>
      </xs:element>
      </xs:schema>

      that imports the "xml" namespace and requires the xml:lang attribute to be specified on the root element, and given this XML

      <?xml version="1.0"?>
      <root attr="1" xml:lang="en" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="xmllang.xsd">
      <tag/>
      </root>

      that does specify the attribute, the command

      SAXPrint -n -s xmllang.xml

      reports:

      Error at file xmllang.xml, line 3, char 46
      Message: Required attribute 'lang' was not provided

      The cause for this is in IGXMLScanner2.cpp, line 206

      // If the uri comes back as the xmlns or xml URI or its just a name
      // and that name is 'xmlns', then we handle it specially. So set a
      // boolean flag that lets us quickly below know which we are dealing
      // with.
      const bool isNSAttr = (uriId == fXMLNSNamespaceId)

      (uriId == fXMLNamespaceId)
      XMLString::equals(suffPtr, XMLUni::fgXMLNSString)
      XMLString::equals(getURIText(uriId), SchemaSymbols::fgURI_XSI);

      When isNSAttr is true, the attribute is not put in the fAttDefRegistry map, that is later used to check if a required attribute has been found in the XML.

      My patch would be to remove the test for (uriId == fXMLNamespaceId) from the expression, because I don't understand why the xml:xxx attributes should be treated in the same special way of xmlns:xxx and xsi:xxx (the latter are really special attributes, but xml:lang and xml:space are not). If xml:xxx must be treated specially because of PSVI, they should at least be put in the map.

      Alberto

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              amassari Alberto Massari
            • Votes:
              4 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: