Reading XML file and skip certain elements/attributes??

Hi folks!
Suppose I have a XML file looking like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE dvds SYSTEM "DTDtest.dtd">
<dvds>
<dvd>
<title>
Aliens
</title>
<director>
James Cameron
</director>
<format>
1.85:1
</format>
</dvd>
<dvd>
<title>
X-Men
</title>
<director>
Bryan Singer
</director>
<format>
2.35:1
</format>
</dvd>
</dvds>
In my Java application I want to read this XML file and print it on the screen (including all tags etc). So far, so good. BUT, if I want to skip certain elements, i.e. all information about the dvd 'X-Men', how am I supposed to do this? In other words, I would like my app to skip reading all information about X-Men and continue with the next <dvd>... </dvd> tag. Is this possible?
My code so far is from the XML tutorial from Sun and it looks like this:
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.helpers.DefaultHandler;
import javax.xml.parsers.SAXParserFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
public class MyXML extends DefaultHandler
public static void main(String argv[]) {
if (argv.length != 1) {
System.err.println("Usage: cmd filename");
System.exit(1);
// Use an instance of ourselves as the SAX event handler
DefaultHandler handler = new MyXML();
// Use the default (non-validating) parser
SAXParserFactory factory = SAXParserFactory.newInstance();
try {
// Set up output stream
out = new OutputStreamWriter(System.out, "UTF8");
// Parse the input
SAXParser saxParser = factory.newSAXParser();
saxParser.parse( new File(argv[0]), handler);
} catch (Throwable t) {
t.printStackTrace();
System.exit(0);
static private Writer out;
//===========================================================
// SAX DocumentHandler methods
//===========================================================
public void startDocument()
throws SAXException
emit("<?xml version='1.0' encoding='UTF-8'?>");
nl();
public void endDocument()
throws SAXException
try {
nl();
out.flush();
} catch (IOException e) {
throw new SAXException("I/O error", e);
* <p>This method prints the start elements including attr.
* @param namespaceURI
* @param lName
* @param qName
* @param attrs
* @throws SAXException
public void startElement(String namespaceURI,
String lName, // local name
String qName, // qualified name
Attributes attrs)
throws SAXException
String eName = lName; // element name
if ("".equals(eName)) eName = qName; // namespaceAware = false
emit("<"+eName);
if (attrs != null) {
for (int i = 0; i < attrs.getLength(); i++) {
String aName = attrs.getLocalName(i); // Attr name
if ("".equals(aName)) aName = attrs.getQName(i);
emit(" ");
emit(aName+"=\""+attrs.getValue(i)+"\"");
emit(">");
public void endElement(String namespaceURI,
String sName, // simple name
String qName // qualified name
throws SAXException
emit("</"+qName+">");
* <p>This method prints the data between 'tags'
* @param buf
* @param offset
* @param len
* @throws SAXException
public void characters(char buf[], int offset, int len)
throws SAXException
String s = new String(buf, offset, len);
emit(s);
//===========================================================
// Utility Methods ...
//===========================================================
// Wrap I/O exceptions in SAX exceptions, to
// suit handler signature requirements
private void emit(String s)
throws SAXException
try {
out.write(s);
out.flush();
} catch (IOException e) {
throw new SAXException("I/O error", e);
// Start a new line
private void nl()
throws SAXException
String lineEnd = System.getProperty("line.separator");
try {
out.write(lineEnd);
} catch (IOException e) {
throw new SAXException("I/O error", e);
Sorry about the long listing... :)
Best regards
/Paul

A possibility that comes to mind is to create an XSLT script to do whatever it is you want - and call it from inside the program. The XSLT script can be stashed inside your .jar file by using getClass().getClassLoader().getResource("...")
- David

Similar Messages

  • Please recommend if we have options to read xml file and insert data into table without a temporary table.

    Please recommend if we have options to read xml file and insert data into table without a temporary table. 

    DECLARE @data XML;
    SET @data =N'<Root>
    <List RecordID="946236" />
    <List RecordID="946237" />
    <List RecordID="946238" />
    <List RecordID="946239" />
    <List RecordID="946240" />
    </Root>'
    INSERT INTO t (id) SELECT T.customer.value('@RecordID', 'INT') AS id
    FROM @data.nodes('Root/List')
     AS T(customer);
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • How to read XML file and update the data in MS CRM 2011?

    Hi Folks,
    Can anyone please help me finding some references to read XML files and push the data to MS CRM 2011 preferably by using a console application.
    Please let me know if any ways of handling it in simple ways.
    Thanks,
    Sri

    HI,
    How to read XML file:
    https://social.msdn.microsoft.com/Forums/en-US/5dd7261b-86c4-4ca8-ba87-95196ef3ba50/need-to-display-xml-file-in-textboxes-edit-the-data-and-save-the-new-xml-file?forum=csharpgeneral
    How to work with CRM:
    ClientCredentials credentials = new ClientCredentials();
    credentials.Windows.ClientCredential = new System.Net.NetworkCredential("USER", "Password", "Domain");
    Uri uri = new Uri("http://server/Organization/XRMServices/2011/Organization.svc");
    OrganizationServiceProxy proxy = new OrganizationServiceProxy(uri, null, credentials, null);
    proxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
    IOrganizationService service = (IOrganizationService)proxy;
    //using "service" you can create, update and retrieve entities.
    More information here about service functions:
    https://msdn.microsoft.com/en-us/library/gg328198.aspx

  • How to read xml file that has changing element names?

    Idon't know much about xml, nor reading it with java, but I have this problem with reading xml file. The file something like this:
    <configuration>
       <DEV001>
          <serial>001</serial>
          <id>number 1</id>
       </DEV001>
       <DEV002>
          <serial>002</serial>
          <id>number 2</id>
       </DEV002>
    </configuration>I have imported the org.w3c.dom.* api, that I use for parsing. I don't know is this a generic or a parser specific issue, but how can I get all the nodes starting with "DEV" into a NodeList?
    If you know a solution for this with another parser, please share it. I have no reason to use that specific parser, I just found a sample using that.
    kari-matti

    Well, NodeList is an interface, so you cannot construct one and put the "good" elements into it. But, you might be able to cast the NodeList with all of the children of the root into an IIOMetadaNode (which is the class that implements the NodeList interface. That class has a removeChild() method that might be able to remove the text nodes and any that don't start with DEV.
    But, if you remove nodes, and still want to do things with the full DOM Document, be very careful and run tests. It may remove those nodes from the full Document.
    If, on the other hand, the printingData( Nodelist nl) method could be modified so it takes an ArrayList or some other collection, it is very simple.
    Just create an ArrayList, and when you find an element starting with DEV, add it to the ArrayList. When you are done, process that list and you are finished.
    Dave Patterson

  • How to read XML file and write into another XML file

    Hi all, I am new to JAVAXML.
    My problem is I have to read one XML file and take some Nodes from that and write these nodes into another XML file...
    I solved, how to read XML file
    But I don't know how to Write nodes into another XML.
    Can anyone help in this???
    Thanks in advance..

    This was answered a bit ago. There was a thread called "XML Mergine" that started on Sept 14th. It has a lot of information about what it takes to copy nodes from one XML Document object into another.
    Dave Patterson

  • Code to read xml file  and display that data using sax parser

    Hai
    My problem I have to read a xml file and display the contents of the file on console using sax parser.

    here you go

  • Read a XML file and store an element to a String

    Hello,
    I'm looking for a solution to load an XML file (see below), read all elements and store the first of them (the first "description" element) in a String variable.
    Should I load the file in a Node variable?
    What is the best solution?
    The XML file looks like:
    <document>
    <typeOfWorkstation >
    <item id="desktop">
    <description>Desktop</description>
    </item>
    <item id="laptop">
    <description>Laptop</description>
    </item>
    <item id="other">
    <description>Other configuration</description>
    </item>
    </typeOfWorkstation>
    </docuement>
    All suggestions will be greatly appreciated
    Thank you
    Sylvain

    no example, uh? the tutorial is packed with code samples
    this will get you started:
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.parse(new File("c:/folder/data.xml"));

  • CS4-JS : Read XML file and getting Attributes

    Dear All,
    How to get the Attributes based on the RootElements.
    For Example:
    //========================== XML File : Start ================================//
    <stag>
         <cust>
            <custname>120</custname>
             <atagst name="alpha" attributename="1" attributevalue="2" sty="First"/>
             <atagst name="beta" attributename="1" attributevalue="5" sty="Second"/>
             <atagst name="gama" attributename="1" attributevalue="2" sty="Third"/>
              <atagst name="theta" attributename="1" attributevalue="5" sty="Fourth"/>
          <cust>
         <cust>
             <custname>121</custname>
              <atagst name="A.alpha" attributename="1" attributevalue="2" sty="First"/>
              <atagst name="A.beta" attributename="1" attributevalue="5" sty="Second"/>
             <atagst name="A.gama" attributename="1" attributevalue="2" sty="Third"/>
              <atagst name="A.theta" attributename="1" attributevalue="5" sty="Fourth"/>
          <cust>
         <cust>
             <custname>122</custname>
              <atagst name="B.alpha" attributename="1" attributevalue="2" sty="First"/>
              <atagst name="Bbeta" attributename="1" attributevalue="5" sty="Second"/>
             <atagst name="B.gama" attributename="1" attributevalue="2" sty="Third"/>
              <atagst name="B.theta" attributename="1" attributevalue="5" sty="Fourth"/>
          <cust>
    </stag>
    //==========================  XML File : End ================================//
    Here I want to check through Java Script Code [InDesign]
    //======================== Script : Starts ====================================//
    var myEveryName = new Array();
    traverse(roots);
      for(var Element_name=0; Element_name<myEveryName.length; Element_name++)
                      if(myEveryName[Element_name] == "customername")
                                      custname.push(myEveryContent[Element_name]);
                    if(myEveryName[Element_name] == "applytagstyle")
                                Aname.push(myEveryAttributes[Element_name][0]);
                                 Aattributename.push(myEveryAttributes[Element_name][1]);
                                 Aattributevalue.push(myEveryAttributes[Element_name][2]);
                                 Asty.push(myEveryAttributes[Element_name][3]);
    function traverse(tree) {
        myEveryName.push(tree.name()); 
        if(tree.elements().length() > 0) {
            for(var i=0; i<tree.elements().length(); i++) {
                traverse(tree.elements()[i]);
    //========================  XML File : End ====================================//
    Everything working fine, but I couldn't get attribute values. Please check the below example
    For Example:
    If you check first root element in above xml code
    i need the output like
    custname=120
    name=alpha,beta,gama,theta
    attributename=1,1,1,1
    attributevalue=2,5,2,5
    sty=first,second,third,fourth
    custname=121
    Please any one can help me and give me the solutions.
    Thanks & Regards
    T.R.Harihara SudhaN

    Few questions:
    1. Your XML is not well formed.
    2. Secondly, I do not see any relation of XML with script. For instance, I do see any elements "customername", "applytagstyle" in input.
    3. Either you have not provided the complete source or either your dummy XML is incorrect.
    Anyways, having a quick look, I guess you are trying to get specific attributes values from XML tree. I will try to give you a kick start though you will be required to customized the script as per requirement (for instance rearranging the attribute values in array and so forth). Otherwise please try to post complete inputs.
    #include "glue code.jsx"
    //Get the attribute values of all elements
    main();
    function main(){
    if (app.documents.length != 0){
    var myDoc = app.activeDocument;
    var myRuleSet = new Array (
    new findObjAttribute("//*")
    with(myDoc){
    var elements = xmlElements;
    __processRuleSet(elements.item(0), myRuleSet);
    else{
    alert("You have no document open!");
    exit();
    function findObjAttribute(XPATH){
    this.name = "findObjAttribute";
    this.xpath = XPATH;
    this.apply = function(myElement, myRuleProcessor)
    var elmName=myElement.markupTag.name;
    with(myElement){
    try {
    var Name=myElement.xmlAttributes.itemByName("name").value;
    var AttName=myElement.xmlAttributes.itemByName("attributename").value;
    var AttValue=myElement.xmlAttributes.itemByName("attributevalue").value;
    var AttSty=myElement.xmlAttributes.itemByName("sty").value;
    $.writeln("Name: "+Name);
    $.writeln("AttributeName: "+AttName);
    $.writeln("AttributeValue: "+AttValue);
    $.writeln("Sty: "+AttSty);
         } catch(e){};
    return true;
    This will just print the values JavaScript console.
    HTH,
    Pankaj Chaturvedi

  • JAVA Read XML file and modify attribute values based on some conditions

    I have the following XML file "C:/Data.xml".
    If the attributes on Dimension, Metirc, Data date Matches then Add the amount values and remove the duplicate DS node.
    I looked some examples on hashtable/hashmapping but I could not find that meets my creiteria. I appriciate any direction or suggestions on this.
    <ED LG="US">
    <DS name="1" source="A" freq="Day">
    <Dimension name="code" value="3">
    <Metric ref_name="A1-ACT">
    <Data date="2011-03-04T00:00:00" amount="30" />
    </Metric>
    </Dimension>
    </DS>
    <DS name="1" source="A" freq="Day">
    <Dimension name="code" value="3">
    <Metric name="A1-ACT">
    <Data date="2011-03-04T00:00:00" amount="40" />
    </Metric>
    </Dimension>
    </DS>
    <DS name="1" source="A" freq="Day">
    <Dimension name="code" value="3">
    <Metric name="A1-ACT">
    <Data date="2011-03-05T00:00:00" amount="20" />
    </Metric>
    </Dimension>
    </DS>
    </ED>
    Expected Result:
    <ED LG="US">
    <DS name="1" source="A" freq="Day">
    <Dimension name="code" value="3">
    <Metric ref_name="A1-ACT">
    <Data date="2011-03-04T00:00:00" amount="70" />
    </Metric>
    </Dimension>
    </DS>
    <DS name="1" source="A" freq="Day">
    <Dimension name="code" value="3">
    <Metric name="A1-ACT">
    <Data date="2011-03-05T00:00:00" amount="20" />
    </Metric>
    </Dimension>
    </DS>
    </ED>
    thanks
    Edited by: user7188033 on Mar 19, 2011 1:40 PM
    Edited by: user7188033 on Mar 19, 2011 2:01 PM
    Edited by: user7188033 on Mar 19, 2011 2:02 PM

    Use XSLT for transforming the XML document.

  • How to read xml file and place it into an internal table...

    hello all,
    can any one help me in - how to read xml data file (placed in application server) and placing the same into an internal table (remove the xml tags or say fetching the xml data without xml tags).

    Hi Murashali,
    use this.
    TYPES: BEGIN OF day,
    name TYPE string,
    work(1) TYPE c,
    END OF day.
    DATA: BEGIN OF week,
    day1 TYPE day,
    day2 TYPE day,
    day3 TYPE day,
    day4 TYPE day,
    day5 TYPE day,
    day6 TYPE day,
    day7 TYPE day,
    END OF week.
    DATA xml_string TYPE string.
    DATA result LIKE week.
    week-day1-name = 'Monday'. week-day1-work = 'X'.
    week-day2-name = 'Tuesday'. week-day2-work = 'X'.
    week-day3-name = 'Wednesday'. week-day3-work = 'X'.
    week-day4-name = 'Thursday'. week-day4-work = 'X'.
    week-day5-name = 'Friday'. week-day5-work = 'X'.
    week-day6-name = 'Saturday'. week-day6-work = ' '.
    week-day7-name = 'Sunday'. week-day7-work = ' '.
    CALL TRANSFORMATION ...
    SOURCE root = week
    RESULT XML xml_string.
    CALL TRANSFORMATION ...
    SOURCE XML xml_string
    RESULT root = result.
    Regards,
    Vijay

  • How to Read Xml File and view into Data Grid View?

    hi all
    my Data into Xml file are:
    <Voucher>
    <Header>
    <txtHeaderId>259803</txtHeaderId>
    <txtDate>2015/02/01</txtDate>
    <txtDocNo>20</txtDocNo>
    <txtMemo>This is a Test .</txtMemo>
    </Header>
    <Item>
    <txtItemId>8562803</txtItemId>
    <txtHeaderRef>259803</txtHeaderRef>
    <txtDesc>This is Number 1</txtDesc>
    <txtDebit>350000</txtDebit>
    <txtCredit>0</txtCredit>
    <txtItemId>8562804</txtItemId>
    <txtHeaderRef>259803</txtHeaderRef>
    <txtDesc>This is Number 2</txtDesc>
    <txtDebit>0</txtDebit>
    <txtCredit>350000</txtCredit>
    </Item>
    </Voucher>
    now i have two DataGridViews 
    i want that data from xml file show into the DataGridViews by this codes:
    Private Sub btnReadXmlFile_Click(sender As Object, e As EventArgs) Handles btnReadXmlFile.Click
    Dim Document As XmlReader = New XmlTextReader(txtPath.Text)
    Dim ds As New DataSet
    ds.ReadXml(Document)
    DataGridView1.DataSource = ds.Tables(0)
    End Sub
    but i see this result:
    why i do not see any result into DataGridView2(Item)
    how to solve it ?
    please help me .
    thanks all
    Name of Allah, Most Gracious, Most Merciful and He created the human

    now how to correct it?
    Name of Allah, Most Gracious, Most Merciful and He created the human
    Please be explicit - I'm the only other one in this thread so I assume it's to me, but usually I just ignore the posts when the user isn't specific.
    I don't know what there is to correct. Create a NEW dataset in code, add the two tables, and use the methods that I suggested.
    I'm not a database guy so I can't get real specific. I create my own stuff in classes and use that but, if you're using SQL then there are lots of pro's here that can help you with specifics. I'm sure they'll need to know a lot more about your data, the
    connection, and all that, but the concept should be fairly simple to implement.
    Still lost in code, just at a little higher level.

  • Read XML file and generate a XLS file?

    Hi Guys,
    How I can generate a XLS file with information in a XML file.
    I have a XML which received information from a form.
    To the user see the information inside a XML file, I created a report.cfm with the informations of the users.
    Now the user want which the information in the XML, generate a XLS file from a CFM file to download.
    How I will transformed this information in a XLS file?
    Thanks,
    Fabiano Magno Pechibella

    There is no need to re-invent the wheel. Raymond Camden has published code that converts information from a form to an Excel file. His method first converts information from a form to a query. But you can easily adapt it to your case. If you do not have direct access to the form, you will still be able to convert the XML data into the name-value pairs in the query.

  • How to Read XML files in OC4J???

    I wrote a Web Application with JBuilder, and deployed it in OC4J.
    In the Web App, there were a class and a Jsp, following:
    in the class:(load the .xml file and get the element's attribute value)import org.jdom.Element;
    import org.jdom.Document;
    import org.jdom.input.SAXBuilder;
    public Document loadXMLDoc(String AFileName) throws Exception
    SAXBuilder lSAXBuilder = new SAXBuilder(false);
    Document lDoc = lSAXBuilder.build(AFileName);
    return lDoc;
    public void testGetXMLValue(String AFileName)
    throws Exception
    Document lDoc = null;
    Element lElement = null;
    Element lElement1 = null;
    try
    lDoc = loadXMLDoc(AFileName);
    lElement = lDoc.getRootElement().getChild("client-setup.xml");
    lElement1 = lElement.getChild("connection-params");
    catch (Exception e)
    e.printStackTrace();
    throw new Exception(lErrorStr);
    in the JSP:(invoking the class's method)<%
    testJspBeanId.testGetXMLValue("client-setup.xml");
    %>
    When compiling the Web App, I had contained the "jdom.jar" and "xerces.jar" packages in .ear file,
    After deploying the .ear in OC4J, the two packages in the "/applications/Web App/Web App/WEB-INF/lib/"
    but when I run the Web App to , Error took place:
    org.jdom.JDOMException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found:in deed:
    "Document lDoc = lSAXBuilder.build(AFileName);" bring on the error,
    but I can't resolve it and I am needing your help!!!
    Thank you.

    import org.dom4j.Document;
    import org.dom4j.DocumentException;
    import org.dom4j.io.SAXReader;
    import java.io.File;
    import java.text.AttributedCharacterIterator.Attribute;
    import java.util.Iterator;
    import java.util.StringTokenizer;
    public class XmlParser
    private String Result="";
    private String Final="";
    private String Delim="";
    public void bar1(Document document) throws DocumentException
    org.dom4j.Element root = document.getRootElement();
    // System.out.println(root.getName());
    bar2(root);
    System.out.println(this.Result);
    process();
    public void bar2(org.dom4j.Element e)
    for(Iterator i = e.elementIterator();i.hasNext();)
    org.dom4j.Element Element = (org.dom4j.Element) i.next();
    Result += Element.getName()+"\t"+Element.getText()+"\n";
    bar2(Element);
    public void process()
    StringTokenizer Tokenizer = new StringTokenizer(this.Result,"\n");
    String element;
    while(Tokenizer.hasMoreTokens())
    element = Tokenizer.nextToken();
    StringTokenizer Tokenizer2 = new StringTokenizer(element,"\t");
    // Do what ever String Process here Example
    this.Final += element.getName();
    this.Final += this.Delim;
    System.out.println(this.Final);
    public static void main(String s[])throws Exception
    Document document = null;
    SAXReader reader = new SAXReader();
    File f1= new File("D:/Rajesh/EDI to XML/EDI.xml");
    document = reader.read(f1);
    Demo obj = new Demo();
    obj.bar1(document);
    i think this will hep full.......

  • Convert xml file into a JDOM Element object?

    Hi,
    I need to convert an xml file into a JDOM Element object.
    I need to do that because I need to pass the JDOM Element object to another method for processing.
    That method takes in a JDOM element object as a single parameter for that method: it was supplied by my supervisor.
    Does anyone knows how to do that?
    Please advice and give me some example.
    Regards.

    Hi,
    You misunderstood me.
    The javaworld article shows you how to convert the xml file to JDOM Document object using SAXBuilder; I am very aware of it as I had done it before.
    Now the problem is tha tI need to convert the xml file to JDOM Element object instead.
    The JDOM Element object contains the whole xml file and that JDOM Element object will be input into a parameter of a method for use.
    Can anyone help?

  • Read in XML file and spit out specific element

    Hi all i wonder if someone could give me a hand. I've got some code (below) which reads in an xml file and spits out the contents of the file. Thats fine and dandy, however what i want to be able to do is specify which element to spit out, which i'm not sure how to do. So say i had the following xml file:
    <?xml version="1.0"?>
    <OpenSourceQuestions>
         <question>
              <setup>A raster graphics editor</setup>
              <answerChoice1>The Gimp</answerChoice1>
              <answerChoice2>The Chimp</answerChoice2>
              <answerChoice3>The Pimp</answerChoice3>
              <answerChoice4>The Blimp</answerChoice4>
              <correctAnswer>The Gimp</correctAnswer>
         </question>
         <question>
              <setup>test question 2</setup>
              <answerChoice1>question2 answer1</answerChoice1>
              <answerChoice2>question2 answer2</answerChoice2>
              <answerChoice3>question2 answer3</answerChoice3>
              <answerChoice4>question2 answer4</answerChoice4>
              <correctAnswer>question2 answer1</correctAnswer>
         </question>
    </OpenSourceQuestions>What i want to do is only spit out the xml for the first question, i.e. "A raster graphics editor" and its answers
    Here is my java code for reading in and arsing the file:
    void readXML(){
                try {
                     File fXmlFile = new File("MyXMLFile.xml");
                     DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
                     DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
                     Document doc = dBuilder.parse(fXmlFile);
                     doc.getDocumentElement().normalize();
                     System.out.println("Root element :" + doc.getDocumentElement().getNodeName());
                     NodeList nList = doc.getElementsByTagName("question");
                     System.out.println("-----------------------");
                     for (int temp = 0; temp < nList.getLength(); temp++) {
                       Node nNode = nList.item(temp);
                       if (nNode.getNodeType() == Node.ELEMENT_NODE) {
                         Element eElement = (Element) nNode;
                         System.out.println("Question : "  + getTagValue("setup",eElement));
                         System.out.println("Answer1 : "  + getTagValue("answerChoice1",eElement));
                         System.out.println("Answer2 : "  + getTagValue("answerChoice2",eElement));
                         System.out.println("Answer3 : "  + getTagValue("answerChoice3",eElement));
                         System.out.println("Answer4 : "  + getTagValue("answerChoice4",eElement));
                } catch (Exception e) {
                  e.printStackTrace();
               private static String getTagValue(String sTag, Element eElement)
                     NodeList nlList= eElement.getElementsByTagName(sTag).item(0).getChildNodes();
                     Node nValue = (Node) nlList.item(0);
                     return nValue.getNodeValue();
               }

    IN the time since i posted i have solved my own query!

Maybe you are looking for