import java.util.*;
import java.io.File;
import java.io.StringReader;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class parse
{
    public static void main(String[] args)
    {
        String xmlFileName = "c:/staxtest/config1.xml";

        try
        {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setValidating(false);
            factory.setIgnoringElementContentWhitespace(false);
            DocumentBuilder builder  = factory.newDocumentBuilder();
            Document document = builder.parse(xmlFileName);

            NodeList nodeList = document.getElementsByTagName("machine_name");
            int x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("machine_name");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("machine_name=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            nodeList = document.getElementsByTagName("prerequisitescript");
            x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("prerequisitescript");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("prerequisitescript=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            nodeList = document.getElementsByTagName("acbuildpath");
            x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("acbuildpath");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("acbuildpath=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            nodeList = document.getElementsByTagName("testsuitscript");
            x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("testsuitscript");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("testsuitscript=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            nodeList = document.getElementsByTagName("vmwarename");
            x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("vmwarename");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("vmwarename=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            nodeList = document.getElementsByTagName("reportname");
            x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("reportname");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("reportname=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            nodeList = document.getElementsByTagName("testdir");
            x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("testdir");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("testdir=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            nodeList = document.getElementsByTagName("testconfig");
            x = nodeList.getLength();
            if (x > 0)
            {
		        nodeList = document.getElementsByTagName("testconfig");
                for (int i = 0; i < nodeList.getLength(); i++)
                {
                    Node node = nodeList.item(i);
                    if (node.getNodeType() == Node.ELEMENT_NODE)
                    {
                        NodeList children = node.getChildNodes();
                        for (int j = 0; j < children.getLength(); j++)
                        {
					        Node thisChild = children.item(j);
                            if (thisChild.getNodeType() == Node.TEXT_NODE)
                                System.out.println("testconfig=" + thisChild.getNodeValue());
                        }
                    }
                }
            }

            Element begin = document.getDocumentElement();
            NodeList nodebegin = begin.getChildNodes();
            String ver = nodebegin.item(1).getNodeName();
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
}
