|
Academic Work Personal
|
Java /
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
|
![]() 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 Places Debrecen | France | Hungary | Montreal | Nancy Notes Hobby Projects * Jabba's Codes Quick Links [ edit ] |