简体   繁体   English

从XML对象提取数据

[英]Extract data from an XML object

How do I extract the data from that XML object, which is a value of a certain array: 如何从该XML对象提取数据,该XML对象是某个数组的值:

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像:

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

...but still, it gets the whole XML object as the field value. ...但仍然,它将整个XML对象作为字段值。 I wanted it to extract the value only not the whole object. 我希望它仅提取值,而不提取整个对象。

All simple xml objects are iteratable. 所有简单的xml对象都是可迭代的。 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. 因此,基本上,我将每个项目从一个对象转换为字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM