1

Using Xerces SAX parser I try to retrieve all elements and their attributes of this XML file:

-------------- Begin XML file to parse ---------------->

<?xml version="1.0" encoding="UTF-8"?> <invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="my.xsd"> <parties> (...)

-------------- End XML file to parse ---------------->

When getting the attributes for the element 'invoice', Xerces++ does not insert the 'xmlns:xsi' attribute in the list of 'Attributes' for the element 'invoice'. However, the attribute 'xsi:noNamespaceSchemaLocation' is inserted in the list.

Why? Is there a specific reason from an XML standard point of view ? Is there a way to configure Xerces++ SAX parser so that it inserts this attribute as well? (The documentation on setting the parser properties does not tell how).

Thanks for your help.

pnuts
  • 58,317
  • 11
  • 87
  • 139
cazdevel
  • 115
  • 1
  • 6

1 Answers1

2

SAX treats namespace declarations differently from attributes. Attributes are notified in the startElement() event, namespaces are notified (if requested) in the startPrefixMapping() event.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164