XmlReader

I’m xml parsing challenged… I’m trying to take the following data and parse it down:

<?xml version="1.0"?>
<RunInstancesResponse xmlns="http://ec2.amazonaws.com/doc/2008-08-08/">
    <requestId>e397a09b-8233-488c-8c17-90ea2088faab</requestId>
    <reservationId>r-2504a54c</reservationId>
    <ownerId>130854919299</ownerId>
    <groupSet>
        <item>
            <groupId>default</groupId>
        </item>
    </groupSet>
    <instancesSet>
        <item>
            <instanceId>i-979321fe</instanceId>
            <imageId>ami-bec226d7</imageId>
            <instanceState>
                0
                <name>pending</name>
            </instanceState>
            <privateDnsName/>
            <dnsName/>
            <reason/>
            <keyName>paygo_keypair</keyName>
            <amiLaunchIndex>0</amiLaunchIndex>
            <instanceType>m1.small</instanceType>
            <launchTime>2008-11-29T06:03:24.000Z</launchTime>
            <placement>
                <availabilityZone>us-east-1a</availabilityZone>
            </placement>
        </item>
    </instancesSet>
</RunInstancesResponse>

So I take this string and do this:

		theResultRaw = poster.getPageData()
			var xmlData = plugins.XmlReader.readXmlDocumentFromString(theResultRaw)
			var theNames = xmlData[0].getChildNodes()
			var theAttributes = xmlData[0].getAttributeNames()
			theResult = null
			for(i = 0; i < theNames.length; i++)
			{
				var currName = theNames[i].getName();  // (theNames[i].getName()).toLowerCase();
				var currValue = theNames[i].getTextValue();
				// set to the field now
				forms[form][currName] = currValue
			}

But the output I get is only the requestid, reservationid and ownerid

I assume I’m not getting the other values because they are child nodes of child nodes.

This should be easy… but I’m new to parsing xml.

Any ideas would bring about cheers and applause here.

Chico

Hi Chico,

I run the code, and it went okey.
Meaning the output for currName was:
requestId
reservationId
ownerId
groupSet
instancesSet

and for currValue it was:
e397a09b-8233-488c-8c17-90ea2088faab
r-2504a54c
130854919299

What version of servoy are you using?

Regards,

Alex