[英]Java reading xml element without prefix but within the scope of a namespace
[英]How to code a default namespace and a namespace with a prefix for single XML element in JAVA
我想要我的xml元素如下
<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">
如果有问题,任何人都可以更正我的代码吗? 帮助将得到极大的应用。
尝试这个 :
我正在使用xom库进行XML-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" />
仍然有一些问题发布给我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.