Results 1 to 2 of 2
  1. #1
    Sangram123 is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Unhappy Parsing XML using Document Builder Factory

    Hi ,

    I have to parse the following XML file using DocumentBuilder Factory:
    This parsing is done in STAF STAX job.

    I am not able to do so properly.Kindly suggest.

    <?xml version="1.0" encoding="utf-8" ?>
    - <operating_system>
    - <unix_80sp1>
    - <tests type="quick_sanity_test">
    <prerequisitescript>preparequicksanityscript</prerequisitescript>
    <acbuildpath>acbuildpath</acbuildpath>
    <testsuitscript>test quick sanity script</testsuitscript>
    <testdir>quick sanity dir</testdir>
    </tests>
    <machine_name>u80sp1_L004</machine_name>
    <machine_name>u80sp1_L005</machine_name>
    <machine_name>xyz.pxy.dxe.cde</machine_name>
    <vmware id="155.35.3.55">144.35.3.90</vmware>
    <vmware id="155.35.3.56">144.35.3.91</vmware>
    </unix_80sp1>
    </operating_system>

    In the above XML file i am able to read values off all tags except:
    "machine_name" and "vmware"

    For machine_name tag , i have to read it and store all the values as a list say

    mach_name which should have the contents [u80sp1_L005,u80sp1_L006,u80sp1_L007]

    also all the vmware attributes should be read into
    vmware_attr which should have the content as :[155.35.3.55,155.35.3.56]

    also all the vmware values should be read into
    vmware_value which should have the content as :
    [144.35.3.90,144.35.3.91]

    The code that i use to parse

    vmware_attr = None
    mach_name = None
    vmware_value = None
    # Get the text value for the element with tag name "machine_name"
    nodeList = document.getElementsByTagName("machine_name")
    for i in range(nodeList.getLength()):
    node = nodeList.item(i);

    if node.getNodeType() == Node.ELEMENT_NODE:
    children = node.getChildNodes()

    for j in range(children.getLength()):
    thisChild = children.item(j)
    if (thisChild.getNodeType() == Node.TEXT_NODE):
    name = thisChild.getNodeValue()
    # Get the text value for the element with tag name "machine_name"
    nodeList = document.getElementsByTagName("machine_name")
    for i in range(nodeList.getLength()):
    node = nodeList.item(i)
    if node.getNodeType() == Node.ELEMENT_NODE:
    children = node.getChildNodes()

    for j in range(children.getLength()):
    thisChild = children.item(j)
    if (thisChild.getNodeType() == Node.TEXT_NODE):
    mach_name = thisChild.getNodeValue()
    (i am able to read here only one value)

    vmware_attr = None
    mach_name = None
    vmware_value = None
    # Get the text value for the element with tag name "machine_name"
    nodeList = document.getElementsByTagName("machine_name")
    for i in range(nodeList.getLength()):
    node = nodeList.item(i);

    if node.getNodeType() == Node.ELEMENT_NODE:
    children = node.getChildNodes()

    for j in range(children.getLength()):
    thisChild = children.item(j)
    if (thisChild.getNodeType() == Node.TEXT_NODE):
    name = thisChild.getNodeValue()
    # Get the text value for the element with tag name "vmware"
    nodeList = document.getElementsByTagName("machine_name")
    for i in range(nodeList.getLength()):
    node = nodeList.item(i)
    if node.getNodeType() == Node.ELEMENT_NODE:
    children = node.getChildNodes()

    for j in range(children.getLength()):
    thisChild = children.item(j)
    if (thisChild.getNodeType() == Node.TEXT_NODE):
    vmware_value = thisChild.getNodeValue()

    (i am able to read here only one value the last one)
    how can i read all the vmware values?

    Also i am not sure as to how i can read the vmware attributes "vmware_attr"


    Kindly suggest.

    Regards
    Sangram

  2. #2
    Sangram123 is offline Member
    Join Date
    Aug 2009
    Posts
    2
    Rep Power
    0

    Default

    Also the imports i am doing to support the coding are :

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

    Also the language use here is jython.

    Regards
    Sangram

Similar Threads

  1. Formula Builder
    By rbs100 in forum Advanced Java
    Replies: 1
    Last Post: 07-03-2009, 07:57 PM
  2. Replies: 0
    Last Post: 03-26-2009, 05:07 PM
  3. Eclipse GUI Builder
    By elebal in forum Eclipse
    Replies: 1
    Last Post: 10-23-2008, 12:38 PM
  4. Creating Document object for XML parsing
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-19-2007, 05:12 PM
  5. Help with NetBeans 5 GUI builder
    By Daniel in forum NetBeans
    Replies: 2
    Last Post: 07-04-2007, 08:08 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •