Using xPath to access values of simpleXML



I have a XML object result from my database containing settings.


I am trying to access the values for a particular settingName:



SimpleXMLElement Object
(
[settings] => Array
(
[0] => SimpleXMLElement Object
(
[settingName] => Test
[settingDescription] => Testing
[requireValue] => 1
[localeID] => 14
[status] => 1
[value] => 66
[settingID] => 5
)

[1] => SimpleXMLElement Object
(
[settingName] => Home Page Stats
[settingDescription] => Show the Top 5 Teammate / Teamleader stats?
[requireValue] => 0
[localeID] => 14
[status] => 0
[value] => SimpleXMLElement Object
(
)

[settingID] => 3
)

)


)


I tried using xPath and have this so far:


$value = $fetchSettings->xpath("//settingName[text()='Test']/../value");


which returns:


Array ( [0] => SimpleXMLElement Object ( [0] => 66 ) )


How can I get the actual value and not just another array/object?


The end result will just be 66 for the example above.


No comments:

Post a Comment