I use SimpleXML pretty much exclusively for this stuff:

$data='';

$xml=simplexml_load_string($data);
foreach ($xml->that as $item){
  print_r($item);
  echo "<hr>";
}

Returns:

SimpleXMLElement Object ( [@attributes] => Array ( [parm1] => a [parm2] => b [parm3] => c ) [0] => red )
SimpleXMLElement Object ( [@attributes] => Array ( [parm1] => e [parm2] => f [parm3] => d ) [0] => blue )

Which is what it should.

You can also use XPath to get at what you want:

$xpath = $xml->xpath('/this/that');

Which would return an array of each <that> item along with the attributes.
Jamie Holly
http://www.intoxination.net 
http://www.hollyit.net

On 3/24/2011 9:09 PM, [email protected] wrote:
When all else fails, and #xml, ##php and #drupal-support come up empty...ask the folks who actually code :)

I have an xml structure that has

<this>
<that parm1="a" parm2="b" parm3="c">red</that>
<that parm1="e" parm2="f" parm3="d">blue</that>
</this>

I've tried simplexml and a few third-party scripts, one that loads the xml into an associative array rather than an object, and nothing lets me get at 'red' or 'blue'.  When I use dsm() on the results, for example, in the case of the object with simplexml I get only one 'that' and do not get its contents. When I use the script that creates the array, I get both that's, and all their parms as elements, but not the colors.

I'm curious what else people are using.

Jeff
--
I am a non sequitur. Beware, the contents were packaged where peanuts are processed.

Ayen Designs
388 Bullsboro Drive #105 · Newnan, Georgia 30263

404-271-9734
Web:ayendesigns.com
Blog: theAccidentalCoder.com
Drupal: j. ayen green (367108)
IRQ: j_ayen_green
IM (Yahoo) baalwww    (MSN) [email protected]
Skype: ayendesigns | Facebook: ayendesigns | Twitter: @ayendesigns



Ayen Designs is the computer services division of


Reply via email to