SAM处理程序的startElement回调中的属性中不存在xmlns属性

时间:2013-07-14 05:05:45

标签: java xml namespaces handler sax

我是SAX和Java的新手,已经实现了SAX默认处理程序并读取了一个xml文件。 当为具有名称空间声明作为属性的xml节点调用startElement时 例如

<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" >

当为此xml节点调用startElement时,我只在attributes中看到targetNamespaceelementFormDefault中的2个属性 我如何获得命名空间声明? 例如,我想做这样的事情。

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

我希望val拥有urn:purchases_2013_1.transactions.webservices.netsuite.com

1 个答案:

答案 0 :(得分:3)

使用startPrefixMapping()和endPrefixMapping()回调将命名空间声明通知给ContentHandler。