PHP使用simplexml_load_file在XML数组中访问数组元素


PHP Accessing emlelments of an array in a XML arrary retrieved with simplexml_load_file

我试图打印一个元素到这个数组(下面的部分列表)。我正在尝试检索customSku元素。我一定不明白如何访问这个元素,这是我的print语句:

print $xml['Item'][0]['customSku'];

print_r($xml);:

SimpleXMLElement Object
(
    [@attributes] => Array
        (
            [count] => 190
            [offset] => 0
            [limit] => 100
        )
    [Item] => Array
        (
            [0] => SimpleXMLElement Object
                (
                    [itemID] => 242
                    [systemSku] => 210000000242
                    [defaultCost] => 23.78
                    [avgCost] => 23.78
                    [tax] => true
                    [archived] => false
                    [itemType] => default
                    [description] => Springfield Offset Extension Post & Pin Stainless Steel - 13" 1610413-0SS
                    [modelYear] => 0
                    [upc] => 038132915572
                    [ean] => SimpleXMLElement Object
                        (
                        )
                    [customSku] => EB-5608042

谢谢你的帮助!

使用[]操作符是为了访问节点属性,这不是您在本例中想要的。

尝试以下操作:

print $xml->Item[0]->customSku;