HOME - Recent Changes - Search:

Academic Work


Personal

* pot de départ


dblp


(:twitter:)

-----

[ edit | logout ]
[ help | sandbox | passwd ]

Helper class for JDOM operations

#############################

/**
 * Common XML manipulations.
 *
 * @author jabba
 */

import java.io.IOException;
import java.io.StringReader;

import org.jdom.Document;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

public class XmlManip 
{
   /**
    * Take a JDOM XML Document and convert it to
    * a pretty-formatted String.
    *
    * @param doc A JDOM XML Document.
    * @return The XML as a nicely formatted String.
    */
   public static String makePrettyXml(Document doc)
   {
      XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat()
                                                 .setOmitDeclaration(true));
      return outp.outputString(doc);
   }

   /**
    * Make an ugly XML pretty.
    *
    * @param xml Ugly XML.
    * @return Pretty XML.
    */
   public static String makePrettyXml(String xml)
   {
      Document doc = parseXmlToJdomDocument(xml);

      return makePrettyXml(doc);
   }

   /**
    * Take an XML as a String and build a JDOM Document
    * from it.
    *
    * @param xml An XML as a string.
    * @return JDOM document of the string.
    */
   public static Document parseXmlToJdomDocument(String xml)
   {
      SAXBuilder parser = new SAXBuilder();
      Document doc = null;

      try {
         doc = parser.build(new StringReader(xml));
      }
      catch (JDOMException e) {
         e.printStackTrace();
      }
      catch (IOException e) {
         e.printStackTrace();
      }

      return doc;
   }

}  // class XmlManip
Cloud City


anime | bash | blogs | bsd | c/c++ | c64 | calc | comics | convert | cube | del.icio.us | digg | east | eBooks | egeszseg | elite | firefox | flash | fun | games | gimp | google | groovy | hardware | hit&run | howto | java | javascript | knife | lang | latex | liferay | linux | lovecraft | magyar | maths | movies | music | p2p | perl | pdf | photoshop | php | pmwiki | prog | python | radio | recept | rts | scala | scene | sci-fi | scripting | security | shell | space | súlyos | telephone | torrente | translate | ubuntu | vim | wallpapers | webutils | wikis | windows


Blogs and Dev.

* Ubuntu Incident
* Python Adventures
* me @ GitHub


Places

Debrecen | France | Hungary | Montreal | Nancy


Notes

full circle | km


Hobby Projects

* Jabba's Codes
* PmWiki
* Firefox
* PHP
* JavaScript
* Scriptorium
* Tutorials
* me @ GitHub


Quick Links


[ edit ]

View - Edit - History - Attach - Print *** Report - Recent Changes - Search
Page last modified on 2010 February 26, 17:07