Extract data from an XML object

只愿长相守 提交于 2020-01-06 05:09:07

问题


How do I extract the data from that XML object, which is a value of a certain array:

Array ( 
   [Title] => SimpleXMLElement Object ( 
      [0] => The Key of Life; A Metaphysical Investigation 
    ) 
   [ASIN] => SimpleXMLElement Object ( [0] => 0982385099 ) ...
 )

I did a foreach of the array like:

foreach ($ArrayName as $FieldLabel => $FieldValue) { 
     $Variable = $FieldValue[0]....
} 

...but still, it gets the whole XML object as the field value. I wanted it to extract the value only not the whole object.


回答1:


All simple xml objects are iteratable. Basically think of any object as a set, and some set's just happen to contain one object.

To extract your value do this

foreach($title as $item)
{
   $list_of_titles = (string) $item;
}
print_r($list_of_titles);

So basically I typecast every item into a string from an object.



来源:https://stackoverflow.com/questions/4917998/extract-data-from-an-xml-object

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!