1

kept trying for hours, brain messed up, need help:

XML-file:

<?xml version="1.0" encoding="UTF-8"?>
<testresult>
  <body>
    <itemset name="sc">
      <item name="1">1</item>
      <item name="2">3</item>
      <item name="3">0</item>
    </itemset>
  </body>
</testresult>

Now I want to retrieve the content (0) of the item with the unique name "3" into $value ...

$value = $resultxml->xpath("//item[@name='$name']");

unfortunately not... what do I need to do to have $value to contain 0?

hakre
  • 184,866
  • 48
  • 414
  • 792
michi
  • 6,525
  • 4
  • 32
  • 53

2 Answers2

2
$results = $xml->xpath("//item[@name='$name']");
$value = (int)$results[0];
interskh
  • 2,471
  • 3
  • 19
  • 20
0

If you want to get the content of the element, you could just cast it to string.

In your case, if you want to get '0', then try:

var_dump((string)$value[0]);
xdazz
  • 154,648
  • 35
  • 237
  • 264