tags:

views:

56

answers:

2

I have an XML file with data stored like this:

<myxml>
<item name="column18">88744544</item>
<item name="column11">47884994</item>
<item name="column3">44788894</item>
</myxml>

I need to first check (and be sure that) column11 is defined (there is no particular order), and then get its value.

Using simple XML is not seeming to work.

I have the following, but the value is missing.

<?php
if (count($xml->myxml->item) > 0)
{
 foreach ($xml->myxml->item as $item)
 {
  var_dump($item->attributes());
 }
}
?>

$item->attributes()->column11 doesn't work.

A: 

Dont include the opening tabs and attributes. For example:

<?php
if (count($xml->item) > 0)
{
 foreach ($xml->item as $item)
 {
  var_dump($item); //For the info
  echo $item['name']; //if you needed the name
 }
}
?>
Redburn
This works, but xpath is much easier for what I'm trying to accomplish. Thanks though.
jwzk
A: 

Try XPath.

if ($xml->xpath('//item[@name="column11"]'))
{
    echo 'exists';
}
Josh Davis
works perfect, thanks.
jwzk