I’m sure something like this will have come up before, but I’m struggling to find what I’m looking for on here at all. I’ve read previous answers here lots of times, but never asked or answered myself before!
I’m using SimpleXML to read a response to an Amazon SimpleDB query, and the result is in the form;
<Item>
<Name>Item 1</Name>
<Attribute>
<Name>Title</Name>
<Value>Item 1 Title</Value>
</Attribute>
<Attribute>
<Name>URL</Name>
<Value>Item 1 URL</Value>
</Attribute>
<Attribute>
<Name>Description</Name>
<Value>Item 1 Description</Value>
</Attribute>
<Attribute>
<Name>Site</Name>
<Value>Item 1 Site</Value>
</Attribute>
</Item>
<Item>
<Name>Item 2</Name>
<Attribute>
<Name>Title</Name>
<Value>Item 2 Title</Value>
</Attribute>
<Attribute>
<Name>URL</Name>
<Value>Item 2 URL</Value>
</Attribute>
<Attribute>
<Name>Description</Name>
<Value>Item 2 Description</Value>
</Attribute>
<Attribute>
<Name>Site</Name>
<Value>Item 2 Site</Value>
</Attribute>
</Item>
I’ve got no problem reading the ‘Name’ at the top of the item, using foreach() in PHP to list all of them, and I have managed to do the same to create a list of ‘Key/Value’ pairs to cycle through listing.
I can’t really figure out how to select, for example, a specific value of description, to place it where I want in a page.
Selecting the Item->Attribute gives an array in the form;
[Name] -> Title
[Value] -> Item 1 Title
And this is where I’m a bit stuck. Still within my existing foreach() cycling through the items, I want an array of the ‘Attributes’, so I can select, for example;
[Title] -> Item 1 Title
[URL] -> Item 1 URL
And so on.
I’m fine selecting the items and echoing their name, bit that’s really as far as I get.
Since this is such a newbie question, I’m sure it’s been asked or answered before, I can’t see an answer anywhere else, so if anyone can point me to one, I’d be very grateful!
Thanks in Advance
In your foreach loop, create a new foreach loop to create an attribute array.
something like
note: Not tested, adjust as needed