Convert Node to String


I receive an XML data to WM flow service via HTTP. IS recognizes the data is XML and auromaticaly converts to com.wm.lang.xml.Document. I need to convert this to String or byte array for archiving and send for further processing.

I am aware that xmlNodeToDocument and documentToXMLString can be used but I’d like to avoid the extra conversion to IData document.

I convert to string using a java transformer, code which proofed several times, but in this case result document has incorrect hierachy. The code is shown below.




<?xml version="1.0" encoding="UTF-8"?>
        <HDR VER="1.0"/>
           <SNDR APPCD="ABC"/>
              <TADDR TADDR="" TADDRTY="IPv4"/>
              <TADDR TADDR="wsi03" TADDRTY="HostName"/>

Note that the result is a complete document not just a part of it.
Elements are closed like it does not have any children. Indenting of the document shows that the hierarchy information is not lost completely.

I guess there is something special about the com.wm.lang.xml.Document implementation which is not interpretted correctly by the transformer.

Would you please give me a hint what is wrong here or how to do the conversion without converting to IData document?

Thank you in advance
Kind regards,

IS version: IS_7.1.2_Core_Fix35
OS: RHEL 5.6
Java: 1.5.0_15 (49.0) Java HotSpot™ 64-Bit Server VM

Transformer code:
IDataCursor pipelineCursor = pipeline.getCursor();
com.wm.lang.xml.Document document = (com.wm.lang.xml.Document) IDataUtil.get( pipelineCursor, “node” );

String xml = “”;
try {
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Result result = new StreamResult(new StringWriter());
Source source = new DOMSource(document);
transformer.transform(source, result);
xml = writer.toString();
catch (Exception e) {}
IDataUtil.put( pipelineCursor, “xml”, xml );

I would say better use builtin out of box rather than using custom Java for this conversion and debugging will be easier and it’s not worth if some thing can do it already for you and it’s reliable XML parser…Just my thoughts:

I too would suggest just using the built-in services to convert to a string. Using a custom Java service to “avoid the extra conversion” seems odd–you’re still doing a conversion.

Another option would be queryXMLNode to retrieve the XML string representation. Using XQL the query is /source()

Yes XQL would be another option:)

Thank you a lot. queryXMLNode exactly suits my needs.