Java XML Namespace stringToDoc(String s, boolean nameSpaceAware)

Here you can find the source of stringToDoc(String s, boolean nameSpaceAware)

Description

/* Parse an XML string into a DOM document

License

Open Source License

Declaration

public static Document stringToDoc(String s, boolean nameSpaceAware)
        throws ParserConfigurationException, SAXException, IOException 

Method Source Code


//package com.java2s;
/*/*from ww w .j ava  2  s . c  om*/
    
Copyright (c) 2009-2011, AOL Inc.
All rights reserved.
    
This code is licensed under a BSD license.
    
*/

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

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class Main {
    /**
    /* Parse an XML string into a DOM document
    */
    public static Document stringToDoc(String s, boolean nameSpaceAware)
            throws ParserConfigurationException, SAXException, IOException {

        DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();

        domFactory.setNamespaceAware(nameSpaceAware);
        DocumentBuilder docBuilder = domFactory.newDocumentBuilder();

        InputSource is = new InputSource();

        is.setCharacterStream(new StringReader(s));
        Document doc = docBuilder.parse(is);

        return doc;
    }
}

Related

  1. isValidFragment(final Object obj, final String namespace, final String localPart)
  2. logWriter(Logger logger, String msg, XMLStreamWriter writer, String namespaceURI)
  3. printNamespace(XMLStreamReader xmlr, int index, StringBuffer result)
  4. printNamespaces(XMLStreamReader xmlr)
  5. readXML(InputStream input, boolean isNamespaceAware)
  6. writeNamespace(XMLStreamWriter out, String prefix, String namespaceURI)
  7. writeNamespace(XMLStreamWriter writer, String prefix, String namespaceURI)
  8. writeNamespaceDeclarations(final XMLStreamWriter writer, final Iterable> prefixes)
  9. writeNamespaceIfNotBound(XMLStreamWriter xmlStream, String prefix, String nsUri)