我是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
中看到targetNamespace
和elementFormDefault
中的2个属性
我如何获得命名空间声明?
例如,我想做这样的事情。
String val = attributes.getValue("xmlns:tranPurch");
我希望val
拥有urn:purchases_2013_1.transactions.webservices.netsuite.com
答案 0 :(得分:3)
使用startPrefixMapping()和endPrefixMapping()回调将命名空间声明通知给ContentHandler。