0
votes

I am using ColdFusion 7 and am new at parsing XML.

I am trying to get at the ID property and extract its value.

<cfset newRate = StructNew()>
<cfset newRate.Carrier = "USPS">
<cfset newRate.Code = Service[i].ID.XmlAttribute>
<cfset newRate.Descr = Service[i].SvcDescription.XmlText>
<cfset newRate.Price = Service[i].Postage.XmlText>

I have tried every combination I can think of to get at the ID property, but nothing works.

Can you help?

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

This returns an array:

<cfset newRate.Code = xmlSearch(Service[i], "/@ID")>

You can view the real XML here;

https://secure.thelowertowngroup.com/steinair/usps/usps_rates_international.cfm

1
What you've posted is not valid XML.Jim Garrison
<cfset newRate.Code = Service[i].ID.XmlAttribute.xmlText> ?charliegriefer
@Jim Garrison - Service[ i ] is the XML. Hard to say whether or not it's valid without seeing it :)charliegriefer
I have included a link to the XML.Evik James
OK how about Service[i].XMLAttributes.ID ? (doing this as comments rather than answers since I'm WAG'ing it a bit)charliegriefer

1 Answers

0
votes

Am needing to do this a bit blind as we can't see your XML (as per my earlier comment, the link you provide is broken).

However... consider THIS code:

<cfxml variable="x">
    <aaa>
        <bbb id="1">
            <id>2</id>
            <ccc></ccc>
            <ccc></ccc>
            <ccc id="3">
                <ddd></ddd>
                <ddd id="4"></ddd>
            </ccc>
        </bbb>
    </aaa>
</cfxml>

<cfoutput>
    #x.aaa.bbb.xmlAttributes["id"]#<br />
    #x.aaa.bbb.id.xmlText#<br />
    #x.aaa.bbb.ccc[3].xmlAttributes["id"]#<br />
    <cfset a = xmlSearch(x, "/aaa/bbb/ccc/ddd[@id]")>
    #a[1].xmlAttributes["id"]#<br />
</cfoutput>

There's some options for fetching IDs. Do any of them help?