Thanks Steeve
Your suggested code works but I changed my mind on my implementation.
After I get the response from SOAP, I want to just take certain nodes from it and copy those nodes to a new document. From there I want to get the XML.
Here is the code I used but importNode() doesn't seem to copy anything.
What am I doing wrong?
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
docOut = builder.newDocument();
NodeList nodeList = m_doc.getElementsByTagName("Export"); // m_doc was also created using DocumentBuilder()
if (nodeList.getLength() == 1)
{
docOut.importNode(nodeList.item(0),true);
}
Transformer transformer = (TransformerFactory.newInstance()).newTransformer();
StringWriter strwriter = new StringWriter();
// DOMSource source = new DOMSource(nodeList.item(0)); // If I use this line instead, I can see the "Export" node
DOMSource source = new DOMSource(docOut);
StreamResult result = new StreamResult(strwriter);
transformer.transform(source, result);
szXML = strwriter.toString();
At this point szXML only contains:
<?xml version="1.0" encoding="UTF-8"?>
Thanks for any help
Jody
-----Original Message-----
From: Steeve Gilbert [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 02, 2001 4:44 PM
To: [EMAIL PROTECTED]
Subject: RE: Working with Xerces
You can get the full explanation here...
http://java.sun.com/xml/jaxp-1.1/docs/tutorial/xslt/2_write.html
They output it to the console but if you wanna get it into a string look at this...
Transformer transformer = (TransformerFactory.newInstance()).newTransformer();
StringWriter strwriter = new StringWriter();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(strwriter);
transformer.transform(source, result);
XMLSTR = strwriter.toString(); //Here you get the string
Good luck!
Steeve...
"Gus Delgado" <[EMAIL PROTECTED]> on 02/08/2001 03:42:15 PM
Please respond to [EMAIL PROTECTED]
To: <[EMAIL PROTECTED]>
cc: (bcc: Steeve Gilbert/G_STGEORGES/CANAM_MANAC)
Subject: RE: Working with Xerces
Document doc = parser.getDocument();
Element� e� = null;
NodeList nl =�doc.getElementsByTagName("tagName");
e = (Element) nl.item(0);
e.normalize();
NodeList nl = e.getChildNodes();
Node textNode = nl.item(0);
String�value =�textNode.getNodeValue()�;
-----Original Message-----
From: Bardman, Jody [mailto:[EMAIL PROTECTED]]
Sent: Thursday, August 02, 2001 2:15 PM
To: [EMAIL PROTECTED]
Subject: Working with Xerces
My SOAP client can build a simple request and send it to the SOAP server
and then receive the response.
I can parse the data.
Now comes the next step:
1). Send a request
2). Receive the XML response.
3). Save the XML.
4). Parse some of the XML response.
5). Add new XML data to what was saved for a new request.
6). Send the new request.
So basically I want to get the response, add to it, and send it out again.
Here is how I was parsing the simple response:
� DOMParser parser = new DOMParser();� //Create a parser
� parser.parse(new InputSource(new StringReader(XMLPref)));� //Create the
DOM
� Document doc = parser.getDocument();
I was hoping to add data by way of the doc/node classes.
How do I get the full XML out of the Document class so I can use it for a
new request?
Thanks
Jody
