Hey folks - I’m accessing a web service that returns “funky” XML as the response:
<result>
<record>
<field name="donor_id" id="donor_id" value="1"/>
<field name="first_name" id="first_name" value="John D."/>
<field name="last_name" id="last_name" value="McClurkin"/>
<field name="middle_name" id="middle_name" value=""/>
</record>
<record>
<field name="donor_id" id="donor_id" value="2"/>
<field name="first_name" id="first_name" value="Bill"/>
<field name="last_name" id="last_name" value="Jones"/>
<field name="middle_name" id="middle_name" value=""/>
</record>
</result>
That’s literally all it returns. There is no default namespace.
So, I thought it would be a piece of cake parsing it using this:
var str = plugins.http.getPageData("myLongURL")
var myXML = new XML(str);
var firstName = myXML.result.record.field.attribute("first_name").toString()
I know that I’m doing something stupid but everything I try just winds up with an empty string.
Then I tried:
var firstName = myXML.result.record[0].field.attribute("first_name").toString()
But that just got an error: ```
TypeError: Cannot read property "field" from undefined
I've already had a look at <a class="postlink-local" href="https://www.servoy.com/forum/viewtopic.php?f=22&t=15818&p=85410">viewtopic.php?f=22&t=15818&p=85410</a> and I guess I'm just missing it.
Any pointers would be greatly appreciated!