cancel
Showing results for 
Search instead for 
Did you mean: 

Java mapping - XML name space

Former Member
0 Kudos

Hi experts,

I doing a java mapping to meet my requirement. I use the following code to produce the target XML

........................................................................

String transactionId = ........................................

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();

// Create the output DOM

Document docOut = builder.newDocument();

Element dashboardInputTypeNode = docOut.createElement("dashboardInputType");

docOut.appendChild(dashboardInputTypeNode);

Element transactionIdNode = docOut.createElement(transactionId);

dashboardInputTypeNode.appendChild(transactionIdNode);

Text transactionIdText = docOut.createTextNode("transactionId");

transactionIdNode.appendChild(transactionIdText);

// transform the new xml to the output stream

TransformerFactory tf = TransformerFactory.newInstance();

Transformer transform = tf.newTransformer();

transform.transform(new DOMSource(docOut), new StreamResult(out));

This code produces me the following XML

<?xml version="1.0" encoding="UTF-8" ?>

<dashboardInputType>

<transactionId>transactionId</transactionId>

</dashboardInputType>

But, I need the XML to be produced with the following namespace

<?xml version="1.0" encoding="UTF-8" ?>

<ns1:dashboardInputType xmlns:ns1="http://www.watercorporation.com.au/dashboard">

<ns1:transactionId>transactionId</ns1:transactionId>

</ns1:dashboardInputType>

what changes do I need to make in my code to get tge desired output?

Reward points for the right answer or doco.

Thanx heaps....

Sabbir

Accepted Solutions (0)

Answers (2)

Answers (2)

GabrielSagaya
Active Contributor
0 Kudos

please visit the link you can understand

GabrielSagaya
Active Contributor
0 Kudos

try this .

docOut.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:ns1","http://www.watercorporation.com.au/dashboard"");