Xml indentation when using recordToDocument

When I do an recordToDocument to convert a record to Sting, the XML generated is indented. Is there a way to removed this indentation.
The reason I need this is because it increases the size of the XML document. We use IS 4.6 & TN

Can you pls elobarate more on your requirement,So that we can help you out.

Thanks,

You could use a pub.string:replace transformer on the XML string and replace its whitespace with nothing.

Using replace will eliminate meaningful whitespace within the tags too, not just the whitespace outside the tags. You might find the package at http://www.wmusers.com/software/uploads/3947customxmlsample.zip to be of help.

> > You could use a pub.string:replace transformer …
> …will eliminate meaningful whitespace within the tags too

Good point Rob! If spaces were removed, my method would also destroy all XML tags with an attribute.

Sorry! I must have been “thinking in xCBL” when I said that. :o]

I guess stripping out ‘\n’ and ‘\r’ would be one quick way provided they don’t occur in the XML data. The SAX parser you pointed to is the best method though.

removeSpace Service Sample
removeSpace.zip (2.4 k)

Try using the service which is attached…
It takes XML as input and gives outputStr as output after removing indentation.

Neat idea, but the service doesn’t work. It removes EVERYTHING that isn’t in a tag–e.g. between ‘<’>’.

I went down this path myself some time ago, hoping to “easily” trim trailing whitespace from data in the tags. The issue is you have to detect the end tag, allow for nested tags, possibly allow for mixed content, and a variety of other special cases. I concluded that for cases such as this it is simply easier to just use an XML parser and a custom XML outputter.

Hi Guys,

We have the same problem as posted by Rob, the output XML that we generate out of recordToDocument is too huge (3-4 MB). What was the conclusion drwan from the discussion conducted earlier ? Or if there is any other solution to reduce the XML size, please let me know.

regds
Radhika

Hi Try using the service which is attached…
It takes XML as input and gives outputXML as output after removing indentation.


TrimXml.zip (2.4 k)

My xml file does not have the root tag…I use map to get values I need from another record and map them to the record generated based on dtd, then use RecordToDocument function, but root tag is missing in xml…what am I missing? Please help, thanks!

XML looks like this:
<senderid>A341</senderid>
<ack_datetime>20010803</ack_datetime>
<invoice_num>A34101023399</invoice_num>
<resend_flag>N</resend_flag>

but it should look like this:

<“1.0”?>
<asn_acknowledgment>
<senderid>A341</senderid>
<ack_datetime>20010803</ack_datetime>
<invoice_num>A34101023399</invoice_num>
<resend_flag>N</resend_flag>
</asn_acknowledgment>

In the RecordToDocument service there is a input parameter (addHeader) set this option to “true” and also there is a parameter for recordName,so specify your recordName (fully qualiffied record name) which will use reference and make well formed.I hope your pipeline boundnode (final document should contain the roottag <asn_acknowledgment>,then only the output xml document will start show the roottag.

Finally your xml will show like this as you are expecting.

<?xml>
<asn_acknowledgment>
<senderid>A341</senderid>
<ack_datetime>20010803</ack_datetime>
<invoice_num>A34101023399</invoice_num>
<resend_flag>N</resend_flag>
</asn_acknowledgment>

HTH.

Margaret,

couple of doubts,

Is your XML record structure created using DTD/Schema or manually?

If you have created the record structure manually then you should first create a record name as(asn_acknowledgment)which is the root or parent tag,followed by child tags or elements below:
<senderid>A341</senderid>
<ack_datetime>20010803</ack_datetime>
<invoice_num>A34101023399</invoice_num>
<resend_flag>N</resend_flag>.

Then using the recordReference on (<asn_acknowledgment>) map the appropriate data to the child elements.Finally the IDATA record will be in the pipe and invoke the recordToDocument Service and just follow my previous post about creating the xml Header tag and well formed document that will have starting with root tag as shown below.

<“1.0”?>
<asn_acknowledgment>
<senderid>A341</senderid>
<ack_datetime>20010803</ack_datetime>
<invoice_num>A34101023399</invoice_num>
<resend_flag>N</resend_flag>
</asn_acknowledgment>

HTH.