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
  • 193,403
  • 52
  • 435
  • 836
michi
  • 6,565
  • 4
  • 33
  • 56

2 Answers2

2
$results = $xml->xpath("//item[@name='$name']");
$value = (int)$results[0];
interskh
  • 2,511
  • 4
  • 20
  • 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
  • 158,678
  • 38
  • 247
  • 274