Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;

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

import org.w3c.dom.Document;
import org.w3c.dom.Node;

public class Main {
    /**
     * Creates a {@link Node} out of a {@link String}
     * 
     * @param xmlString
     *            never <code>null</code>
     * @return the string as node, never <code>null</code>
     */
    public static Node asNode(String xmlString) throws Exception {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        factory.setNamespaceAware(true);
        DocumentBuilder builder = factory.newDocumentBuilder();
        ByteArrayInputStream is = new ByteArrayInputStream(xmlString.getBytes());
        try {
            Document wfsCapabilities = builder.parse(is);
            return wfsCapabilities.getDocumentElement();
        } finally {
            is.close();
        }
    }
}