Xerces SAX parser ignore the xmlxs:xsi attribute as an attribute of an element

950 views Asked by At

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.

1

There are 1 answers

0
Michael Kay On BEST ANSWER

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