Java XML Parse String parse(String xml)

Here you can find the source of parse(String xml)

Description

Parse a XML document from string

License

Open Source License

Declaration

public static Document parse(String xml) throws Exception 

Method Source Code

//package com.java2s;
/**//www  . j av a 2s .c  o m
 * Copyright 2017 Institute of Computing Technology, Chinese Academy of Sciences.
 * Licensed under the terms of the Apache 2.0 license.
 * Please see LICENSE file in the project root for terms
 */

import org.w3c.dom.Document;

import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import java.io.StringReader;

public class Main {
    /** Parse a XML document from string */
    public static Document parse(String xml) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(xml));
        return builder.parse(is);
    }
}

Related

  1. parse(String s)
  2. parse(String text)
  3. parse(String xml)
  4. parse(String xml)
  5. parse(String xml)
  6. parse(String xml)
  7. parseAccessNumber(String line)
  8. parseAddressLines(String[] addressLines)
  9. parseArg(String arg)