我有象下面这样的XML,W3C XML元素得到与命名空间和没有命名空间
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Entities xmlns="sample">
<Entity>
sample Value
</Entity>
<ns1:Entity xmlns:ns1="sample">
sample Value
</ns1:Entity>
</Entities>
当我使用nodeElement.getNodeName();
,我只能抽到<Entity>
不<ns1:Entity>
。
我验证了this post并尝试了getLocalName()
而不是getNodeName()
。它不工作。此外,当我尝试使用getElementByTagNameNS("Entity","sample")
,所述getLength()
方法返回的0
更新:
如以下回答我互换getElementByTagNameNS
上述参数。 我看到一个使用getElementByTagNameNS("*","Entity")
的选项,它允许我不对代码中的命名空间进行硬编码。现在想知道,使用*
有没有什么缺点。
请显示验证码。 – 2013-03-04 12:39:19