Many, many thanks Tracy - I thought I had tried something along those lines without success but your suggestion fits the bill perfectly.
Paul Newton
-----Original Message----- From: ProfoxTech [mailto:profoxtech-bounces@leafe.com] On Behalf Of Tracy Pearson Sent: 21 March 2016 16:54 To: profoxtech@leafe.com Subject: RE: Need help with parsing XML
Paul Newton wrote on 2016-03-21:
Hi all
I have the following simplified XML
<Formats> <Bank id="1" name="AIB"> <Content text = "line1" value="value1"/> <Content text = "line2" value="value2"/> </Bank> <Bank id="2" name="Barclays"> <Content text = "line1" value="value1"/> <Content text = "line2" value="value2"/> <Content text = "line3" value="value3"/> </Bank> </Formats>
With the following code I can iterate through the banks and display their
names as follows
goXML = CREATEOBJECT('MSXML2.DomDocument') goXML.Load("Formats.XML") gcolElements = goxml.getElementsByTagName("Bank") For Each element In gcolElements ? element.attributes.item(0).text,element.attributes.item(1).text EndFor
But for each bank I need to iterate through the content entries for that
bank and extract the text and value attributes. So far I cannot see how to do it. Any suggestions would be very welcome
Many thanks
Paul Newton
Paul,
There are multiple ways to parse the XML DomDocument. You grabbed all the elements called "Bank", you could then grab the elements called "Content" or loop through the child nodes.
goXML = CREATEOBJECT('MSXML2.DomDocument') goXML.Load("Formats.XML") gcolElements = goxml.getElementsByTagName("Bank") For Each element In gcolElements ? element.attributes.item(0).text,element.attributes.item(1).text IF element.haschildnodes FOR EACH content IN element.childNodes ? content.attributes.item(0).text, content.attributes.item(1).text NEXT ENDIF EndFor
Tracy Pearson PowerChurch Software
[excessive quoting removed by server]