All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vladsch.flexmark.docx.converter.util.XmlFormatter Maven / Gradle / Ivy

There is a newer version: 0.64.8
Show newest version
package com.vladsch.flexmark.docx.converter.util;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.bootstrap.DOMImplementationRegistry;
import org.w3c.dom.ls.DOMImplementationLS;
import org.w3c.dom.ls.LSSerializer;
import org.xml.sax.InputSource;

import javax.xml.parsers.DocumentBuilderFactory;
import java.io.StringReader;

/**
 * Pretty-prints xml, supplied as a string.
 * 

* eg. * {@code * String formattedXml = XmlFormatter.format("hello"); * } *

* StackOverflow: https://stackoverflow.com/questions/139076/how-to-pretty-print-xml-from-java */ public class XmlFormatter { public static String format(String xml) { try { InputSource src = new InputSource(new StringReader(xml)); Node document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src).getDocumentElement(); Boolean keepDeclaration = Boolean.valueOf(xml.startsWith("





© 2015 - 2024 Weber Informatics LLC | Privacy Policy