【发布时间】:2014-05-24 10:14:29
【问题描述】:
我正在尝试用 Java 为 Android 构建一个简单的 XML DOM。这工作正常,但 Android 命名空间前缀始终设置为“ns0”,但它应该是“android”
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
doc = factory.newDocumentBuilder().newDocument();
doc.setXmlStandalone(true);
Element manifest = doc.createElement("manifest");
manifest.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:android",NS_ANDROID);
manifest.setAttributeNS(NS_ANDROID, "versionName", "bla");
doc.appendChild(manifest);
我得到的输出如下:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ns0="http://schemas.android.com/apk/res/android" ns0:versionName="bla"/>
我需要改变什么才能得到以下结果:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionName="bla"/>
【问题讨论】:
标签: java xml xml-namespaces