on 12-07-2007 12:09 AM
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
please visit the link you can understand
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try this .
docOut.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:ns1","http://www.watercorporation.com.au/dashboard"");
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.