Search code examples
javaxmlnamespaceshandlersax

xmlns attribute not present in attributes in startElement callback of SAX handler


I am new to SAX and Java, have implemented SAX default handler and reading an xml file. When startElement is called for an xml node which has namespace declaration as attributes e.g.

<schema xmlns="http://www.w3.org/2001/XMLSchema" 
    xmlns:tranPurch="urn:purchases_2013_1.transactions.webservices.netsuite.com" 
    xmlns:tranPurchTyp="urn:types.purchases_2013_1.transactions.webservices.netsuite.com" 
    xmlns:platformCore="urn:core_2013_1.platform.webservices.netsuite.com" 
    xmlns:platformCoreTyp="urn:types.core_2013_1.platform.webservices.netsuite.com" 
    xmlns:platformCommon="urn:common_2013_1.platform.webservices.netsuite.com" 
    xmlns:platformCommonTyp="urn:types.common_2013_1.platform.webservices.netsuite.com" 
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="urn:purchases_2013_1.transactions.webservices.netsuite.com" 
    elementFormDefault="qualified" >

When startElement gets called for this xml node, I am only seeing 2 attributes inside attributes which are targetNamespace and elementFormDefault How do I get the namespace declarations as well? for example, I want to do something like this.

String val = attributes.getValue("xmlns:tranPurch");

And I expect val to have urn:purchases_2013_1.transactions.webservices.netsuite.com


Solution

  • Namespace declarations are notified to the ContentHandler using the startPrefixMapping() and endPrefixMapping() callbacks.