Hi ,
What i intend do to is actually considering the input xml.
<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>
Read all machine_name tag values in a list as :
(u80sp1_L004,u80sp1_L005,xyz.pxy.dxe.cde)
Read all vmware tags attributes into one list as : (155.35.3.55,155.35.3.56)
Read all vmware values into one list as : (144.35.3.90,144.35.3.91)
What now i am able to read is machine_name = xyz.pxy.dxe.cde(the last one)
vmware = 144.35.3.91(the last value).
Regards
Sangram
On Thu, Jul 30, 2009 at 9:32 PM, Sangram Bakshi <san...@gmail.com> wrote:
>
> Hi David,
>
> Thanks for the information.
>
> Actually what i wanto achieve is to read the following xml file:
>
>
> <?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>
>
> For a single tag i am able to get the values for e.g:
> <acbuildpath>acbuildpath</acbuildpath>
>
> by using the following piece of code:
>
> nodeList = document.getElementsByTagName("acbuildpath")
> 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):
> acbuildpath = thisChild.getNodeValue()
>
> so now acbuildpath gives me the value in tag acbuild path:
> This goes fine.
>
> Now in the same xml file there is a tag "machine_name". This tag appears
> thrice in the xml file .What i want to achieve is read all these values in a
> list variable. So i am not sure what correction i should do in the code so
> that i can capture all the three "machine_name" tag values from the
> mentioned xml file.
>
> Also there is a tag named as "vmware" in the xml file .The format of the
> tag is <vmware id="155.35.3.55">144.35.3.90</vmware>
> There are two tags like this .
>
> Here in the tag the first ip is the attribute of the tag , and second is
> the value of the tag. I want to read all attributes into a list
> and all the values into another list.(as there are two such tags).
>
> So what correction i need to do in the above code to achieve this.
>
> Kinldy suggest(it would be a time saver). I am also trying to solve in
> between by looking in the internet materials that you have suggested.
>
>
> Regards
> Sangram
>
>
>
>
>
>
> On Thu, Jul 30, 2009 at 7:54 PM, David Bender <bda...@us.ibm.com> wrote:
>
>>
>> I'm not sure exactly what's wrong with your job, but we provide the
>> following STAX job: http://staf.sourceforge.net/current/getLatest.xml which
>> you may want to use as an example, since it does some similar
>> processing (for example it parses for multiple <file> elements).
>>
>> Actually the DocumentBuilderFactory and related classes are Java classes
>> (not Jython), so searching on the web for the following should provide some
>> useful links.
>>
>> javax.xml.parsers.DocumentBuilderFactory
>> javax.xml.parsers.DocumentBuilder
>> org.w3c.dom.Document
>> org.w3c.dom.Element
>> org.w3c.dom.Node
>> org.w3c.dom.NodeList
>>
>> Thanks,
>> David
>>
>> ------------------------------
>> *David
>> Bender*<http://w3.ibm.com/bluepages/simpleSearch.wss?searchBy=Name&searchFor=David+Bender>
>> STAF/STAX Development
>> IBM Software Group, WPLC
>> 11501 Burnet Rd.
>> Bldg. 903-5B002
>> Austin, TX 78758-3400
>> Phone (T/L): 1-512-286-5315 (363-5315)
>> ITN: 23635315
>> Email: *bda...@us.ibm.com* <bda...@us.ibm.com>
>>
>>
>> ------------------------------
>>
>>
>>
>> *Sangram Bakshi <san...@gmail.com>*
>>
>> 07/30/2009 05:17 AM
>> To
>> staf-users@lists.sourceforge.net cc
>> Subject
>> [staf-users] Parsing a xml file using document builder factory.
>>
>>
>>
>>
>> Hi ,
>>
>> This is not really related to STAF and STAX , but would be a time saver .I
>> am quite new to jython xml parsing using document builder.
>> I am trying to read a xml file of the following format in the staf and
>> stax job xml file:
>>
>> <?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>
>>
>> Here machine_name tag can be n number. I need to read all the machine_name
>> tags in an array , so that i can use them later.
>> Also i need to read all the vmware tags in an array (both value and
>> attributes) so that i can use them later. The number of vmware tags can
>> again be n numbers.
>>
>> I am trying the following code :
>>
>> <!-- *******************************************************************
>> -->
>> <!-- Following function is used to parse an XML file and return the DOM
>> -->
>> <!-- document object
>> -->
>> <!-- *******************************************************************
>> -->
>> <function name="parseXML" scope="local">
>> <function-list-args>
>> <function-required-arg name="xmlFileName">
>> Name of file containing XML to be parsed
>> </function-required-arg>
>> </function-list-args>
>> <sequence>
>> <!-- Parse the XML -->
>> <script>
>> factory = DocumentBuilderFactory.newInstance();
>> factory.setValidating(1)
>> factory.setIgnoringElementContentWhitespace(0)
>> builder = factory.newDocumentBuilder()
>> document = builder.parse(xmlFileName)
>>
>> </script>
>> <script>
>>
>> vmware = None
>> machine_name = None
>>
>> # Get the text value for the element with tag name "vmware"
>> nodeList = document.getElementsByTagName("vmware")
>> 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):
>> machine_name = thisChild.getNodeValue()
>>
>> # Get the text value for the element with tag name "machine_name"
>> nodeList = document.getElementsByTagName("vmware")
>> 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):
>> machine_name = thisChild.getNodeValue()
>>
>> </script>
>> <return>[machine_name,vmware]</return>
>> </sequence>
>> </function>
>>
>>
>> I am able to read only one value for machine_name (u80sp1_L005) and also
>> one value for vmware
>> i.e 144.35.3.91.
>>
>> Also a good link to understand parsing in jython using doumentbilder
>> factory would be good help.
>>
>> Regards
>> Sangram
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day
>> trial. Simplify your report design, integration and deployment - and focus
>> on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now.
>> http://p.sf.net/sfu/bobj-july_______________________________________________
>> staf-users mailing list
>> staf-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/staf-users
>>
>>
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users