Java Utililty Methods XML Node to String

List of utility methods to do XML Node to String

Description

The list of methods to do XML Node to String are organized into topic(s).

Method

StringtoWellKnowName(Node vertexStyleNode)
to Well Know Name
if (vertexStyleNode == null) {
    return "";
String value = "square";
try {
    NamedNodeMap atts = vertexStyleNode.getAttributes();
    String nodeVal = atts.getNamedItem("class").getNodeValue();
    if (nodeVal.indexOf("Square") > -1) {
...
voidtoWriter(Node node, Writer writer, Map outputProperties)
Writes an XML node to a writer.
try {
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    for (Map.Entry<String, String> property : outputProperties.entrySet()) {
        try {
            transformer.setOutputProperty(property.getKey(), property.getValue());
        } catch (IllegalArgumentException e) {
    DOMSource source = new DOMSource(node);
    StreamResult result = new StreamResult(writer);
    transformer.transform(source, result);
} catch (TransformerConfigurationException e) {
} catch (TransformerFactoryConfigurationError e) {
StringtoXML(Node node)
Xml to string.
try {
    Source source = new DOMSource(node);
    StringWriter stringWriter = new StringWriter();
    Result result = new StreamResult(stringWriter);
    TransformerFactory factory = TransformerFactory.newInstance();
    Transformer transformer = factory.newTransformer();
    transformer.transform(source, result);
    return stringWriter.getBuffer().toString();
...
StringtoXml(Node node)
Returns String representation of the the XML node (document or element).
Source source = new DOMSource(node);
StringWriter writer = new StringWriter();
Result result = new StreamResult(writer);
Transformer t = TransformerFactory.newInstance().newTransformer();
t.transform(source, result);
return writer.toString();
StringtoXml(Node node)
to Xml
Source src = new DOMSource(node);
return toXml(src, -1);
StringtoXML(Node node)
Takes a Node object and converts it to a String representing the valid XML structure.
Transformer tf = TransformerFactory.newInstance().newTransformer();
tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
tf.setOutputProperty(OutputKeys.INDENT, "yes");
tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
Writer out = new StringWriter();
tf.transform(new DOMSource(node), new StreamResult(out));
return out.toString();
...
StringtoXml(Node node, boolean keepHeader)
to Xml
Transformer transformer;
DOMSource xmlSource = new DOMSource(node);
transformer = TransformerFactory.newInstance().newTransformer();
StringWriter writer = new StringWriter();
StreamResult outputTarget = new StreamResult(writer);
transformer.transform(xmlSource, outputTarget);
String str = writer.getBuffer().toString();
if (!keepHeader)
...
StringtoXMLString(final Node value)
to XML String
return toXMLString(new DOMSource(value));
StringtoXMLString(Node node)
to XML String
if (node == null) {
    return "";
try {
    Transformer tran = tf.newTransformer();
    tran.setOutputProperty(OutputKeys.INDENT, "yes");
    StringWriter swriter = new StringWriter();
    Source src = new DOMSource(node);
...
StringtoXMLString(Node node)
to XML String
ByteArrayOutputStream baos = new ByteArrayOutputStream();
writeToStream(baos, node);
return new String(baos.toByteArray(), "UTF-8");