Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

Printing the content of an XML tree



Several methods in the XMLNodeUtilities and XMLNodeUtilities2 allow to print the content of an XML tree, either in a File, URL, or String.

For the XMLNodeUtilities: For the XMLNodeUtilities2:

Using a custom serializer

It is possible to customize the serializer used to print nodes. The methods allow to se a custom NodeSerializer as an argument to the print method. For example:
You can define your own serializer by implementing the interface or overriding the AbstractNodeSerializer class.

Control over the attributes order

By default the attributes of each node will be srialized in alphabetical order. However it is posssible to specify that you want the attributes serialized in the order in which they have been added to their node. Each print method has a version which allow you to specify which order you want. For example:
   XMLRoot root = ...
   File file = ..;
   XMLNodeUtilities.print(root, 2, file); // use the default alphabetical order for attributes
   XMLNodeUtilities.print(root, 2, true, file); // serialize the attributes in the order in which they have been added to their node

If the isOrdered argument is true, then the attributes will be serialized in the order in which they have been added to their node. This means that if you get the node tree from a String or a File or URL, and then print the tree, then the order of the attributes in the String, the File or the URL will be preserved in the result.

See also


Categories: packages | xml

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences