2014-09-30 74 views
1

爲單個XML元素前綴命名空間我想我的XML元素如下如何編寫一個默認的命名空間,並與JAVA

<exElement xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema"> 

我用下面的代碼

rootElement.setAttributeNS("urn:hl7-org:v3", "xsd", "http://www.w3.org/2001/XMLSchema"); 

,給我元素如下,這是不同於我想要的。

<exElement xmlns:ns0="urn:hl7-org:v3" xsi:ns1="http://www.w3.org/2001/XMLSchema"> 

任何人都可以請糾正我的代碼,如果有問題?幫助將大大appriciated。

回答

1

試試這個:

我使用xomXML-manipulation

Element root = new Element("exElement"); 
root.addNamespaceDeclaration("xsi","http://www.w3.org/2001/XMLSchema"); 
root.setNamespaceURI("urn:hl7-org:v3"); 

Document document = new Document(root); 
System.out.println("XML :: " + document.toXML()); 

是工作的罰款,我&給我的結果是:

XML :: <?xml version="1.0"?> 
<exElement xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema" /> 

仍存在一些問題發表了我。

相關問題