Example usage for org.w3c.dom Document setXmlStandalone

List of usage examples for org.w3c.dom Document setXmlStandalone

Introduction

In this page you can find the example usage for org.w3c.dom Document setXmlStandalone.

Prototype

public void setXmlStandalone(boolean xmlStandalone) throws DOMException;

Source Link

Document

An attribute specifying, as part of the <a href='http://www.w3.org/TR/2004/REC-xml-20040204#NT-XMLDecl'>XML declaration</a>, whether this document is standalone.

Usage

From source file:Main.java

License:asdf

public static void main(String args[]) throws Exception {
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder(); // Create the parser
    Document xmlDoc = builder.parse(new InputSource(new StringReader(xmlString)));

    xmlDoc.setXmlStandalone(true);

}

From source file:Main.java

public static Document createDocument(boolean standalone) throws ParserConfigurationException {
    DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
    f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, Boolean.TRUE);
    DocumentBuilder b = f.newDocumentBuilder();
    Document d = b.newDocument();
    d.setXmlStandalone(standalone);
    return d;// w w w. j av a  2 s.c o m
}

From source file:Main.java

public static Document createDocument(String mainType, String customType) throws ParserConfigurationException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document document = builder.newDocument();
    document.setXmlStandalone(false);
    Element sync = document.createElement("Sync");
    document.appendChild(sync);// ww  w  .jav  a2s. c o  m
    Element entity = document.createElement("Entity");
    entity.setAttribute("mainType", mainType);
    if (customType.length() > 0)
        entity.setAttribute("customType", customType);
    document.getElementsByTagName("Sync").item(0).appendChild(entity);
    return document;
}

From source file:Main.java

public static Document newDocument() {
    final DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
    final DocumentBuilder docBuilder;
    try {/*from w ww  . j a  v a  2 s .  c  o m*/
        docBuilder = dbfac.newDocumentBuilder();
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
    final Document document = docBuilder.newDocument();
    document.setXmlStandalone(true);
    return document;
}

From source file:Main.java

public static Document convertToDocument(Node node) throws ParserConfigurationException {

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(false);/*from w  w w .  ja  v a  2 s .co m*/
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document newDocument = builder.newDocument();
    newDocument.setXmlStandalone(true);
    Node importedNode = newDocument.importNode(node, true);
    newDocument.appendChild(importedNode);
    return newDocument;
}

From source file:Main.java

/**
 * Adds stylesheet informations to an xml document. See
 * <a href='http://stackoverflow.com/questions/2651647/add-xml-stylesheet-and-get-standalone-yes'>Stack Overflow</a>.
 *
 * @param aDocument/*from  ww  w .ja  v  a 2  s . c  o m*/
 * @param aFilename
 */
public static void addStylesheet(Document aDocument, String aFilename) {

    aDocument.setXmlStandalone(true);

    Element root = aDocument.getDocumentElement();

    String data = DATA_STYLESHEET.replace(LOCATION_PLACEHOLDER, aFilename);
    ProcessingInstruction processingInstruction = aDocument.createProcessingInstruction(TARGET_STYLESHEET,
            data);

    aDocument.insertBefore(processingInstruction, root);
}

From source file:Main.java

/**
 * Create a new, empty XML document//ww  w.ja v  a  2  s.c o m
 * @return A new, empty XML document
 */
public static Document xml() {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    try {
        Document d = factory.newDocumentBuilder().newDocument();
        d.setXmlStandalone(true);
        return d;
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e);
    }
}

From source file:Main.java

public static Document readXml(File xmlFile) throws IllegalArgumentException {
    try {/*from ww w  .  j  a v  a2 s .c  om*/
        Document document = newDocumentBuilder().parse(xmlFile);
        document.setXmlStandalone(true);
        return document;
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    } catch (SAXException e) {
        throw new IllegalArgumentException(e);
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static Document readXml(InputStream inputStream) {
    try {//from w  w w.j  a  va  2 s  . c om
        Document document = newDocumentBuilder().parse(inputStream);
        document.setXmlStandalone(true);
        return document;
    } catch (IOException e) {
        throw new IllegalArgumentException(e);
    } catch (SAXException e) {
        throw new IllegalArgumentException(e);
    } catch (ParserConfigurationException e) {
        throw new IllegalStateException(e);
    }
}

From source file:Main.java

public static final Document createDocument(boolean standalone, String xmlVersion) {
    Document result = null;

    try {//from  www . j a  va  2s.c  om

        result = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
        result.setXmlStandalone(standalone);
        result.setXmlVersion(xmlVersion);
    } catch (ParserConfigurationException e) {

        e.printStackTrace();
    }

    return result;
}