0

Can some tell me the function similar to normalize() of DOM in JDOM? I actually want to normalize the XML content and serialise it through XMLSerializer.

Thank You Sam

waldyr.ar
  • 14,424
  • 6
  • 33
  • 64
  • and I don't thinkwe have XML Serializer in JDOM, what is the quivalent class used for that? Can also someone help me with this too. Thank You – Sandeep Govind Jul 19 '12 at 21:27

1 Answers1

0

Sandeep.

JDOM does not have a direct 'normalize' concept. Writing one would not be particularly hard, though. On the other hand, your intention is to output the XML in some format, and all the JDOM Output mechanisms will normalize the data for you.

So, for example, if you want to output the JDOM document as plain XML text, you can use the XMLOutputter class in org.jdom2.output and use an appropriate org.jdom2.output.Format instance (say, Format.getPrettyFormat() - do not use getRawFormat() as the raw formatter will not normalize the output at all).

In addition to outputting the JDOM document as text-based XML, you can also output to a DOM document, a SAX even stream, and even StAX streams. Each of these will produce a 'Normalized' output.

So, what you want to do (probably), is to:

Document mudoc = .....;
XMLOutputter xout = new XMLOutputter(Format.getPrettyFormat());
xout.output(mydoc, somestream);

Rolf

rolfl
  • 17,539
  • 7
  • 42
  • 76
  • Thanks Rolf yes,my aim is to output the entire content present in JDOM document to a file usng FileOutPutStream. I know it to express it in DOM as follows - File=new FIle(some path of file); FileOutputSTream fs=new FileOutputStream(file); document.getDocumentelement().normalize(); OutputFormat format=new OutputFormat(document); XMLSerializer serial=new XMLSerializer(fs,format); serial.asDOMserializer(); serial.serialize(document.getDocumentElement(); I think i have to write this in JDOM as XMLOutputter xout=new XMLOutputter(Format.getCompactFormat()); xout.output(jdomdoc,fs); Is this right? – Sandeep Govind Jul 19 '12 at 23:34