Java XML Parse File parseXml(String value, boolean isFile)

Here you can find the source of parseXml(String value, boolean isFile)

Description

parse Xml

License

Open Source License

Declaration

public static Element parseXml(String value, boolean isFile) 

Method Source Code


//package com.java2s;
//License as published by the Free Software Foundation; either

import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import java.io.StringReader;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

public class Main {
    public static Element parseXml(String value, boolean isFile) {
        Element element = null;/*from w w  w. jav  a2s .co  m*/

        try {
            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder domBuilder = domFactory.newDocumentBuilder();

            if (isFile) {
                element = domBuilder.parse(value).getDocumentElement();
            } else {
                element = domBuilder.parse(new InputSource(new StringReader(value))).getDocumentElement();
            }
        } catch (Exception e) {
        }

        return element;
    }
}

Related

  1. parseXML(final File file)
  2. parseXml(String fileName)
  3. parseXml(String filename, boolean validating)
  4. parseXml(String filePath)
  5. parseXml(String filePath)
  6. parseXMLFile(File f)
  7. parseXmlFile(File file)
  8. parseXmlFile(File file, boolean validating)
  9. parseXMLFile(final File xmlFile)