Home > DeveloperSection > Forums > Default namespace with prefix for single XML element in JAVA
Goti Bandu

Total Post:119

Points:835
Posted on    November-05-2014 10:56 PM

 XML Java 
Ratings:


 1 Reply(s)
 685  View(s)
Rate this:
I want my xml element as follows

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

I used the following code

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

And gives me the Element as follows which is different than what i want.

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

Can anyone please correct my code if there is an issue? Help will be greatly appriciated.



marcel ethan
marcel ethan

Total Post:105

Points:735
Posted on    November-06-2014 12:47 AM

Try this :

I am using xom library for 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());

that's working fine for me & give me result :

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

still some problem post me.


Don't want to miss updates? Please click the below button!

Follow MindStick