Trouble getting an XML Element

I have the following…


<imagesXML>
<channel>
   <item><media:content url="http://s3.amazonaws.com/bucket/1.jpg" medium="image"/></item>
   <item><media:content url="http://s3.amazonaws.com/bucket/2.jpg" medium="image"/></item>
   <item><media:content url="http://s3.amazonaws.com/bucket/3.jpg" medium="image"/></item>
</channel>
</imagesXML>

I need to get the url of the second url attribute.

imagesXML.channel.item.count() works but media@content or media.content@url wont. media:content@url is invalid syntax (of course). I cannot change the XML.

You’ll need to user getNamedElement() to get nodes with namespaces. You may need to break it into multiple statements, but something like this should work:

xml.channel.item[0].getNamedElements("media:content")[0]@url

“TheEndless” wrote:
You’ll need to user getNamedElement() to get nodes with namespaces. You may need to break it into multiple statements, but something like this should work:

xml.channel.item[0].getNamedElements("media:content")[0]@url

Actually can do it even simpler, because ifXMLList supports getNamedElements() just like ifXMLElement does (i.e. no need to zero-in on the exact element just yet)

xml.channel.item.getNamedElements("media:content") 

But then will still have to add [idx]@url for the specific attribute as needed - because GetAttributes() does not work the same way for ifXMLList, so one cannot do

xml.channel.item.getNamedElements("media:content").getAttributes().url   'No good
xml.channel.item.getNamedElements("media:content")@url   'No good
'but this will do
xml.channel.item.getNamedElements("media:content")[idx]@url   'OK with single row

I like to give credit to roXML when it deserves it: it has some… affordances :slightly_smiling_face:

Thanks a lot! Works perfectly.