Hello Everybody,
I am generating a XML using Java Parsers(JAXP,DOM). The XML itself is well-formed and
1. When viewed thru the IE it comes all with line-breaks, indendation and looks like a good formatted XML (hope u understand what i mean)
But When I open it with notepad, wordpad or anything else, the XML is displayed in one single very long line.
Please let me know how to produce the XML with line breaks, indendation. Basically format it in similar way as it appears in IE. I used XMLSPY and there is an option to do this, but i want to do it programatically. The XML gets transferred from Windows to Unix and longer lines causes problems in transfer.
Also cannot use JDOM because the formatter needs org.jdom.Document whereas my entire tier is structured around org.w3c.dom.Document.
Thanks for your efforts in advance.
-
Formatting XML with LF - URGENT (4 messages)
- Posted by: Bharani Kannan
- Posted on: July 25 2003 14:24 EDT
Threaded Messages (4)
- Formatting XML with LF - URGENT by Kalin Komitski on July 28 2003 04:53 EDT
- Formatting XML with LF - URGENT by Bharani Kannan on July 28 2003 15:19 EDT
- Formatting XML with LF - URGENT by Kalin Komitski on July 29 2003 04:04 EDT
- Formatting XML with LF - URGENT by Bharani Kannan on July 28 2003 15:19 EDT
- Formatting XML with LF - URGENT by Race Condition on September 12 2003 18:25 EDT
-
Formatting XML with LF - URGENT[ Go to top ]
- Posted by: Kalin Komitski
- Posted on: July 28 2003 04:53 EDT
- in response to Bharani Kannan
Hello Everybody,
>
> I am generating a XML using Java Parsers(JAXP,DOM). The XML itself is well-formed and
>
> 1. When viewed thru the IE it comes all with line-breaks, indendation and looks like a good formatted XML (hope u understand what i mean)
>
> But When I open it with notepad, wordpad or anything else, the XML is displayed in one single very long line.
>
> Please let me know how to produce the XML with line breaks, indendation. Basically format it in similar way as it appears in IE. I used XMLSPY and there is an option to do this, but i want to do it programatically. The XML gets transferred from Windows to Unix and longer lines causes problems in transfer.
>
> Also cannot use JDOM because the formatter needs org.jdom.Document whereas my entire tier is structured around org.w3c.dom.Document.
>
> Thanks for your efforts in advance.
You can use the following example code (and Xerces for XML parsing):
OutputFormat format = new OutputFormat(newCatalog, "UTF-8", true);
format.setLineWidth(0);
XMLSerializer serializer = new XMLSerializer(new FileWriter(outputDirectory + "/BooksCAT/catalog.xml"), format);
serializer.serialize(newCatalog.getDocumentElement());
Hope this helps
Kalin -
Formatting XML with LF - URGENT[ Go to top ]
- Posted by: Bharani Kannan
- Posted on: July 28 2003 15:19 EDT
- in response to Kalin Komitski
Hi kalin,
thanks for the reply. I did try the Serializer. But it did not work. It can still serialize to no. of destiantions/formats but cannot format the XML. -
Formatting XML with LF - URGENT[ Go to top ]
- Posted by: Kalin Komitski
- Posted on: July 29 2003 04:04 EDT
- in response to Bharani Kannan
In order to format the output you need to create OutputFormat object and set the last parameter to true in the corresponding constructor (as shown above).
Setting this parameter to true will format the XML in the usual way as you are used to see it in IE for example. If you use Xerces and use the example code I think you'll get what you want (I haven't tried it with different XML parsers)
Kalin -
Formatting XML with LF - URGENT[ Go to top ]
- Posted by: Race Condition
- Posted on: September 12 2003 18:25 EDT
- in response to Bharani Kannan
If it is so god-damned URGENT, figure it out on your own and don't waste your time at this forum.