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.
SAX treats namespace declarations differently from attributes. Attributes are notified in the startElement() event, namespaces are notified (if requested) in the startPrefixMapping() event.
精彩评论