my dog learned polymorphism*
The moose likes XML and Related Technologies and the fly likes How to append an xml string within a xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "How to append an xml string within a xml" Watch "How to append an xml string within a xml" New topic
Author

How to append an xml string within a xml

Mrinal Bhattacharjee
Greenhorn

Joined: Jul 16, 2012
Posts: 2
I am supposed to insert a piece of xml string withing an xml doc. I have created an xml string using DOM. A Web service will accept this string as an input and create the master xml. My child xml looks ok but after passing to the web service it looks
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body>
<importOrder xmlns="http://abc.def.ghi.com"><orderfile>
<?xml version="1.0" encoding="UTF-8" standalone="
no"?><orders><order cancel="0" orderKey="
01"><Subscriber cancel="0"><identifier>
256322315015</identifier></Subscriber><devices><device
cancel="0"><deviceKey>8ED</deviceKey></device>
</devices></order></orders></orderfile></importOrder>
</soapenv:Body></soapenv:Envelope>

PLEASE Suggest a solution
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Hi Mrinal,

Welcome to the Ranch.

To append a child element, you can use the appendChild() method in org.w3c.dom.Node class.

So when you get a child node like a String, you parse it to a DOM document and append the created child node with the existing parent node you already have.

I am not sure though why your input String is appended with the SOAP wsdl (I guess).
Mrinal Bhattacharjee
Greenhorn

Joined: Jul 16, 2012
Posts: 2
Thanks for your prompt reply. But the issue i m facing is my work is to generate the child string and send it to an API. API will automatically incorporate the child xml. Issue is that i send in XML format.. for eg "<a>hello</a>". But the API converts it into "< hello >". and as a result parser flags an error
John Jai
Bartender

Joined: May 31, 2011
Posts: 1776
Mrinal Bhattacharjee wrote:But the API converts it into "< hello >". and as a result parser flags an error

Please be more specific. Can you please post the code you use to generate the XML string?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18118
    
    8

When you say "insert an XML string", you don't explain what you have to do. So could you clarify: do you have to insert that string as text, or as XML markup?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to append an xml string within a xml
 
Similar Threads
SOAP Validation Help Requested
XML in Payload, fault returned.
Axis message style "SAAJ" ????
problem with perl web services and java client
Axis Fault: no such operation