PHP:从XML集合获取结果
我试图用PHP读取XML文件,但我无法获取数据,也不知道为什么 XML结构:PHP:从XML集合获取结果,php,loops,xml,Php,Loops,Xml,我试图用PHP读取XML文件,但我无法获取数据,也不知道为什么 XML结构: <?xml version="1.0" encoding="UTF-8"?> <FavoriteListResponse> <metadata> <offset>0</offset> <limit>20</limit> <total>1</total> </m
<?xml version="1.0" encoding="UTF-8"?>
<FavoriteListResponse>
<metadata>
<offset>0</offset>
<limit>20</limit>
<total>1</total>
</metadata>
<favorites>
<favorites objectType="Product">
<id>5831fd52f9f0c0a80c88dafa</id>
<productId>511290702</productId>
<imageId>39d5e666255e351aa42fca3a9b939d04</imageId>
<product>
<id>511290702</id>
<name>Misha Black Cropped Leather Jacket With Asymmetrical Front Zipper</name>
<brandedName>Mackage Misha Black Cropped Leather Jacket With Asymmetrical Front Zipper</brandedName>
<unbrandedName>Misha Black Cropped Leather Jacket With Asymmetrical Front Zipper</unbrandedName>
<currency>USD</currency>
<price>620.0</price>
<priceLabel>Sold Out</priceLabel>
<inStock>false</inStock>
<stock>
<stock>
<size>
<name>M</name>
</size>
</stock>
<stock>
<size>
<name>XXS</name>
</size>
</stock>
</stock>
<retailer>
<id>596</id>
<name>Mackage</name>
<score>242</score>
</retailer>
<brand>
<id>1590</id>
<name>Mackage</name>
</brand>
<locale>en_US</locale>
<description>Misha by Mackage is a washed leather jacket for women crafted from genuine lambskin. Fitted silhouette cropped above the hips. Asymmetrical full-length zip closure. Dual zippered front pockets. Nickel hardware. Available in black and sand. Fits true to size. Fitted silhouette. Washed genuine lambskin leather jacket. Cropped above the hips. Padded shoulder yoke. Hem yoke with stitching at the back bottom. Asymmetrical full-length two-way zip closure. Nickel hardware. Coat length from shoulder to hem : 17inches / 43.2cm Model is 5'11/180 cm and wearing a size XS. Shell: 100% Lambskin. Lining (Woven): 100% Polyester.</description>
<clickUrl>https://api.shopstyle.com/action/apiVisitRetailer?id=511290702&pid=uid5044-35323862-95</clickUrl>
<image>
<sizes>
<Small>
<sizeName>Small</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg</url>
<width>32</width>
<height>40</height>
<actualWidth>11</actualWidth>
<actualHeight>40</actualHeight>
</Small>
<XLarge>
<sizeName>XLarge</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_xlarge.jpg</url>
<width>328</width>
<height>410</height>
<actualWidth>111</actualWidth>
<actualHeight>410</actualHeight>
</XLarge>
<Medium>
<sizeName>Medium</sizeName>
<url>https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>112</width>
<height>140</height>
<actualWidth>38</actualWidth>
<actualHeight>140</actualHeight>
</Medium>
<Large>
<sizeName>Large</sizeName>
<url>https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>164</width>
<height>205</height>
<actualWidth>55</actualWidth>
<actualHeight>205</actualHeight>
</Large>
<IPhoneSmall>
<sizeName>IPhoneSmall</sizeName>
<url>https://img.shopstyle-cdn.com/mim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg</url>
<width>100</width>
<height>125</height>
<actualWidth>34</actualWidth>
<actualHeight>125</actualHeight>
</IPhoneSmall>
<Best>
<sizeName>Best</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_best.jpg</url>
<width>720</width>
<height>900</height>
<actualWidth>243</actualWidth>
<actualHeight>900</actualHeight>
</Best>
<Original>
<sizeName>Original</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_best.jpg</url>
<actualWidth>243</actualWidth>
<actualHeight>900</actualHeight>
</Original>
<IPhone>
<sizeName>IPhone</sizeName>
<url>https://img.shopstyle-cdn.com/mim/39/d5/39d5e666255e351aa42fca3a9b939d04.jpg</url>
<width>288</width>
<height>360</height>
<actualWidth>97</actualWidth>
<actualHeight>360</actualHeight>
</IPhone>
</sizes>
<id>39d5e666255e351aa42fca3a9b939d04</id>
</image>
<alternateImages>
<alternateImages>
<sizes>
<Small>
<sizeName>Small</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg</url>
<width>32</width>
<height>40</height>
<actualWidth>11</actualWidth>
<actualHeight>40</actualHeight>
</Small>
<XLarge>
<sizeName>XLarge</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_xlarge.jpg</url>
<width>328</width>
<height>410</height>
<actualWidth>111</actualWidth>
<actualHeight>410</actualHeight>
</XLarge>
<Medium>
<sizeName>Medium</sizeName>
<url>https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>112</width>
<height>140</height>
<actualWidth>38</actualWidth>
<actualHeight>140</actualHeight>
</Medium>
<Large>
<sizeName>Large</sizeName>
<url>https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>164</width>
<height>205</height>
<actualWidth>55</actualWidth>
<actualHeight>205</actualHeight>
</Large>
<IPhoneSmall>
<sizeName>IPhoneSmall</sizeName>
<url>https://img.shopstyle-cdn.com/mim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg</url>
<width>100</width>
<height>125</height>
<actualWidth>34</actualWidth>
<actualHeight>125</actualHeight>
</IPhoneSmall>
<Best>
<sizeName>Best</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_best.jpg</url>
<width>720</width>
<height>900</height>
<actualWidth>243</actualWidth>
<actualHeight>900</actualHeight>
</Best>
<Original>
<sizeName>Original</sizeName>
<url>https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_best.jpg</url>
<actualWidth>243</actualWidth>
<actualHeight>900</actualHeight>
</Original>
<IPhone>
<sizeName>IPhone</sizeName>
<url>https://img.shopstyle-cdn.com/mim/39/d5/39d5e666255e351aa42fca3a9b939d04.jpg</url>
<width>288</width>
<height>360</height>
<actualWidth>97</actualWidth>
<actualHeight>360</actualHeight>
</IPhone>
</sizes>
<id>39d5e666255e351aa42fca3a9b939d04</id>
</alternateImages>
<alternateImages>
<sizes>
<Small>
<sizeName>Small</sizeName>
<url>https://img.shopstyle-cdn.com/pim/56/c4/56c4c2a990fb868e7a27a57381330244_small.jpg</url>
<width>32</width>
<height>40</height>
<actualWidth>12</actualWidth>
<actualHeight>40</actualHeight>
</Small>
<XLarge>
<sizeName>XLarge</sizeName>
<url>https://img.shopstyle-cdn.com/pim/56/c4/56c4c2a990fb868e7a27a57381330244_xlarge.jpg</url>
<width>328</width>
<height>410</height>
<actualWidth>124</actualWidth>
<actualHeight>410</actualHeight>
</XLarge>
<Medium>
<sizeName>Medium</sizeName>
<url>https://img.shopstyle-cdn.com/sim/56/c4/56c4c2a990fb868e7a27a57381330244_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>112</width>
<height>140</height>
<actualWidth>42</actualWidth>
<actualHeight>140</actualHeight>
</Medium>
<Large>
<sizeName>Large</sizeName>
<url>https://img.shopstyle-cdn.com/sim/56/c4/56c4c2a990fb868e7a27a57381330244/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>164</width>
<height>205</height>
<actualWidth>62</actualWidth>
<actualHeight>205</actualHeight>
</Large>
<IPhoneSmall>
<sizeName>IPhoneSmall</sizeName>
<url>https://img.shopstyle-cdn.com/mim/56/c4/56c4c2a990fb868e7a27a57381330244_small.jpg</url>
<width>100</width>
<height>125</height>
<actualWidth>38</actualWidth>
<actualHeight>125</actualHeight>
</IPhoneSmall>
<Best>
<sizeName>Best</sizeName>
<url>https://img.shopstyle-cdn.com/pim/56/c4/56c4c2a990fb868e7a27a57381330244_best.jpg</url>
<width>720</width>
<height>900</height>
<actualWidth>273</actualWidth>
<actualHeight>900</actualHeight>
</Best>
<Original>
<sizeName>Original</sizeName>
<url>https://img.shopstyle-cdn.com/pim/56/c4/56c4c2a990fb868e7a27a57381330244_best.jpg</url>
<actualWidth>273</actualWidth>
<actualHeight>900</actualHeight>
</Original>
<IPhone>
<sizeName>IPhone</sizeName>
<url>https://img.shopstyle-cdn.com/mim/56/c4/56c4c2a990fb868e7a27a57381330244.jpg</url>
<width>288</width>
<height>360</height>
<actualWidth>109</actualWidth>
<actualHeight>360</actualHeight>
</IPhone>
</sizes>
<id>56c4c2a990fb868e7a27a57381330244</id>
</alternateImages>
<alternateImages>
<sizes>
<Small>
<sizeName>Small</sizeName>
<url>https://img.shopstyle-cdn.com/pim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c_small.jpg</url>
<width>32</width>
<height>40</height>
<actualWidth>10</actualWidth>
<actualHeight>40</actualHeight>
</Small>
<XLarge>
<sizeName>XLarge</sizeName>
<url>https://img.shopstyle-cdn.com/pim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c_xlarge.jpg</url>
<width>328</width>
<height>410</height>
<actualWidth>108</actualWidth>
<actualHeight>410</actualHeight>
</XLarge>
<Medium>
<sizeName>Medium</sizeName>
<url>https://img.shopstyle-cdn.com/sim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>112</width>
<height>140</height>
<actualWidth>37</actualWidth>
<actualHeight>140</actualHeight>
</Medium>
<Large>
<sizeName>Large</sizeName>
<url>https://img.shopstyle-cdn.com/sim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>164</width>
<height>205</height>
<actualWidth>54</actualWidth>
<actualHeight>205</actualHeight>
</Large>
<IPhoneSmall>
<sizeName>IPhoneSmall</sizeName>
<url>https://img.shopstyle-cdn.com/mim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c_small.jpg</url>
<width>100</width>
<height>125</height>
<actualWidth>33</actualWidth>
<actualHeight>125</actualHeight>
</IPhoneSmall>
<Best>
<sizeName>Best</sizeName>
<url>https://img.shopstyle-cdn.com/pim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c_best.jpg</url>
<width>720</width>
<height>900</height>
<actualWidth>236</actualWidth>
<actualHeight>900</actualHeight>
</Best>
<Original>
<sizeName>Original</sizeName>
<url>https://img.shopstyle-cdn.com/pim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c_best.jpg</url>
<actualWidth>236</actualWidth>
<actualHeight>900</actualHeight>
</Original>
<IPhone>
<sizeName>IPhone</sizeName>
<url>https://img.shopstyle-cdn.com/mim/a9/b2/a9b2551df3fe88d30f596ab83a1e764c.jpg</url>
<width>288</width>
<height>360</height>
<actualWidth>94</actualWidth>
<actualHeight>360</actualHeight>
</IPhone>
</sizes>
<id>a9b2551df3fe88d30f596ab83a1e764c</id>
</alternateImages>
<alternateImages>
<sizes>
<Small>
<sizeName>Small</sizeName>
<url>https://img.shopstyle-cdn.com/pim/b8/2a/b82a3ff82915a288cedb59386eb74c4c_small.jpg</url>
<width>32</width>
<height>40</height>
<actualWidth>11</actualWidth>
<actualHeight>40</actualHeight>
</Small>
<XLarge>
<sizeName>XLarge</sizeName>
<url>https://img.shopstyle-cdn.com/pim/b8/2a/b82a3ff82915a288cedb59386eb74c4c_xlarge.jpg</url>
<width>328</width>
<height>410</height>
<actualWidth>114</actualWidth>
<actualHeight>410</actualHeight>
</XLarge>
<Medium>
<sizeName>Medium</sizeName>
<url>https://img.shopstyle-cdn.com/sim/b8/2a/b82a3ff82915a288cedb59386eb74c4c_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>112</width>
<height>140</height>
<actualWidth>39</actualWidth>
<actualHeight>140</actualHeight>
</Medium>
<Large>
<sizeName>Large</sizeName>
<url>https://img.shopstyle-cdn.com/sim/b8/2a/b82a3ff82915a288cedb59386eb74c4c/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>164</width>
<height>205</height>
<actualWidth>57</actualWidth>
<actualHeight>205</actualHeight>
</Large>
<IPhoneSmall>
<sizeName>IPhoneSmall</sizeName>
<url>https://img.shopstyle-cdn.com/mim/b8/2a/b82a3ff82915a288cedb59386eb74c4c_small.jpg</url>
<width>100</width>
<height>125</height>
<actualWidth>35</actualWidth>
<actualHeight>125</actualHeight>
</IPhoneSmall>
<Best>
<sizeName>Best</sizeName>
<url>https://img.shopstyle-cdn.com/pim/b8/2a/b82a3ff82915a288cedb59386eb74c4c_best.jpg</url>
<width>720</width>
<height>900</height>
<actualWidth>250</actualWidth>
<actualHeight>900</actualHeight>
</Best>
<Original>
<sizeName>Original</sizeName>
<url>https://img.shopstyle-cdn.com/pim/b8/2a/b82a3ff82915a288cedb59386eb74c4c_best.jpg</url>
<actualWidth>250</actualWidth>
<actualHeight>900</actualHeight>
</Original>
<IPhone>
<sizeName>IPhone</sizeName>
<url>https://img.shopstyle-cdn.com/mim/b8/2a/b82a3ff82915a288cedb59386eb74c4c.jpg</url>
<width>288</width>
<height>360</height>
<actualWidth>100</actualWidth>
<actualHeight>360</actualHeight>
</IPhone>
</sizes>
<id>b82a3ff82915a288cedb59386eb74c4c</id>
</alternateImages>
<alternateImages>
<sizes>
<Small>
<sizeName>Small</sizeName>
<url>https://img.shopstyle-cdn.com/pim/e4/9d/e49db198c964ac5c339b2924687c633c_small.jpg</url>
<width>32</width>
<height>40</height>
<actualWidth>32</actualWidth>
<actualHeight>40</actualHeight>
</Small>
<XLarge>
<sizeName>XLarge</sizeName>
<url>https://img.shopstyle-cdn.com/pim/e4/9d/e49db198c964ac5c339b2924687c633c_xlarge.jpg</url>
<width>328</width>
<height>410</height>
<actualWidth>328</actualWidth>
<actualHeight>410</actualHeight>
</XLarge>
<Medium>
<sizeName>Medium</sizeName>
<url>https://img.shopstyle-cdn.com/sim/e4/9d/e49db198c964ac5c339b2924687c633c_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>112</width>
<height>140</height>
<actualWidth>112</actualWidth>
<actualHeight>140</actualHeight>
</Medium>
<Large>
<sizeName>Large</sizeName>
<url>https://img.shopstyle-cdn.com/sim/e4/9d/e49db198c964ac5c339b2924687c633c/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg</url>
<width>164</width>
<height>205</height>
<actualWidth>164</actualWidth>
<actualHeight>205</actualHeight>
</Large>
<IPhoneSmall>
<sizeName>IPhoneSmall</sizeName>
<url>https://img.shopstyle-cdn.com/mim/e4/9d/e49db198c964ac5c339b2924687c633c_small.jpg</url>
<width>100</width>
<height>125</height>
<actualWidth>100</actualWidth>
<actualHeight>125</actualHeight>
</IPhoneSmall>
<Best>
<sizeName>Best</sizeName>
<url>https://img.shopstyle-cdn.com/pim/e4/9d/e49db198c964ac5c339b2924687c633c_best.jpg</url>
<width>720</width>
<height>900</height>
<actualWidth>720</actualWidth>
<actualHeight>900</actualHeight>
</Best>
<Original>
<sizeName>Original</sizeName>
<url>https://img.shopstyle-cdn.com/pim/e4/9d/e49db198c964ac5c339b2924687c633c_best.jpg</url>
</Original>
<IPhone>
<sizeName>IPhone</sizeName>
<url>https://img.shopstyle-cdn.com/mim/e4/9d/e49db198c964ac5c339b2924687c633c.jpg</url>
<width>288</width>
<height>360</height>
<actualWidth>288</actualWidth>
<actualHeight>360</actualHeight>
</IPhone>
</sizes>
<id>e49db198c964ac5c339b2924687c633c</id>
</alternateImages>
</alternateImages>
<extractDate>2016-02-16</extractDate>
<lastModified>2017-02-05</lastModified>
<seeMoreLabel>Mackage Leather Jackets</seeMoreLabel>
<preOwned>false</preOwned>
<rental>false</rental>
<colors />
<sizes>
<size>
<name>XXS</name>
<canonicalSize>
<id>79</id>
<name>XXS (0)</name>
</canonicalSize>
</size>
<size>
<name>M</name>
<canonicalSize>
<id>85</id>
<name>M (8-10)</name>
</canonicalSize>
</size>
</sizes>
<categories>
<category>
<id>leather-jackets</id>
<name>Leather Jackets</name>
<shortName>Leather</shortName>
<fullName>Women's Leather Jackets</fullName>
<localizedId>leather-jackets</localizedId>
</category>
</categories>
<badges />
</product>
<date>
<date>2016-11-20</date>
<timestamp>1479671122</timestamp>
<friendly>Nov 20, 2016</friendly>
</date>
<objectId>511290702</objectId>
</favorites>
</favorites>
</FavoriteListResponse>
0
20
1.
5831fd52f9f0c0a80c88dafa
511290702
39D5E66255E351AA42FCA3A9B939D04
511290702
Misha黑色裁剪皮夹克,正面不对称拉链
Mackage Misha黑色裁剪皮夹克,正面不对称拉链
Misha黑色裁剪皮夹克,正面不对称拉链
美元
620
票已售完
假的
M
XXS
596
麦卡奇
242
1590
麦卡奇
恩努斯
Misha by Mackage是一款为女性设计的水洗皮夹克,由纯正羊皮制成。臀部上方剪裁修身剪裁。不对称全长拉链。双拉链前口袋。镍制五金。黑色和沙色可选。大小合适。合身的轮廓。水洗纯正羊皮皮夹克。臀部以上的。软垫肩轭。下摆轭与缝合在后面底部。不对称全长双向拉链。镍制五金。上衣从肩部到下摆的长度:17英寸/43.2厘米型号为5'11/180厘米,尺码为XS。外壳:100%羊皮。衬里(机织):100%聚酯纤维。
https://api.shopstyle.com/action/apiVisitRetailer?id=511290702&pid=uid5044-35323862-95
小的
https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg
32
40
11
40
XLarge
https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_xlarge.jpg
328
410
111
410
中等
https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg
112
140
38
140
大的
https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg
164
205
55
205
IPhoneSmall
https://img.shopstyle-cdn.com/mim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg
100
125
34
125
最好的
https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_best.jpg
720
900
243
900
起初的
https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_best.jpg
243
900
苹果手机
https://img.shopstyle-cdn.com/mim/39/d5/39d5e666255e351aa42fca3a9b939d04.jpg
288
360
97
360
39D5E66255E351AA42FCA3A9B939D04
小的
https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg
32
40
11
40
XLarge
https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_xlarge.jpg
328
410
111
410
中等
https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04_medium/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg
112
140
38
140
大的
https://img.shopstyle-cdn.com/sim/39/d5/39d5e666255e351aa42fca3a9b939d04/mackage-misha-black-cropped-leather-jacket-with-asymmetrical-front-zipper.jpg
164
205
55
205
IPhoneSmall
https://img.shopstyle-cdn.com/mim/39/d5/39d5e666255e351aa42fca3a9b939d04_small.jpg
100
125
34
125
最好的
https://img.shopstyle-cdn.com/pim/39/d5/39d5e666255e351aa42fca3a9b939d04_best.jpg
720
900
/**
* Class xml2array
*/
class xml2array {
var $arrOutput = array();
var $resParser;
var $strXmlData;
function parse($strInputXML) {
$this->resParser = xml_parser_create ();
xml_set_object($this->resParser,$this);
xml_set_element_handler($this->resParser, "tagOpen", "tagClosed");
xml_set_character_data_handler($this->resParser, "tagData");
$this->strXmlData = xml_parse($this->resParser,$strInputXML );
if(!$this->strXmlData) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->resParser)),
xml_get_current_line_number($this->resParser)));
}
xml_parser_free($this->resParser);
return $this->arrOutput;
}
function tagOpen($parser, $name, $attrs) {
$tag=array("name"=>$name,"attrs"=>$attrs);
array_push($this->arrOutput,$tag);
}
function tagData($parser, $tagData) {
if(trim($tagData)) {
if(isset($this->arrOutput[count($this->arrOutput)-1]['tagData'])) {
$this->arrOutput[count($this->arrOutput)-1]['tagData'] .= $tagData;
}
else {
$this->arrOutput[count($this->arrOutput)-1]['tagData'] = $tagData;
}
}
}
function tagClosed($parser, $name) {
$this->arrOutput[count($this->arrOutput)-2]['children'][] = $this->arrOutput[count($this->arrOutput)-1];
array_pop($this->arrOutput);
}
}
$xml_file = file_get_contents('yourxmlfilename.xml');
$objXML = new xml2array();
$arrOutput = $objXML->parse($xml_file);
print '<pre>';
print_r($arrOutput); //print it out, or do whatever!
print '</pre>';
function actionFindDataByXMLTag( $result, $xml_tag, $xml_end_tag, $count = null ) {
$next_string = '';
$result_array = array();
$stop = 500;//only 500 items values will be selected
$i = 0;
while($i < $stop) {
if($next_string == '') {
$from = $result;
} else {
$from = $next_string;
}
$position = strpos($from, $xml_tag) + strlen($xml_tag);
$start = substr($from, $position);
$end = strpos($start, $xml_end_tag);
$terr_result = substr($start, 0, $end);
if($terr_result == '') {
break;
} else {
array_push($result_array, $terr_result);
}
$next_string = substr($start, $end + strlen($xml_end_tag));
//var_dump( $next_string );
$i++;
}
return $result_array;
}
<?php
error_reporting ( E_ALL );
ini_set ( 'display_errors', 1 );
$xml = simplexml_load_file('t1.xml');
foreach( $xml->favorites->favorites->product as $product ){
echo "Product name=".(string)$product->name.PHP_EOL;
echo "Retailer=".(string)$product->retailer->name.PHP_EOL;
foreach ( $product->sizes->size as $size ) {
echo "Size:".(string)$size->name.PHP_EOL;
}
echo "Small image=".(string)$product->image->sizes->Small->url;
}
Product name=Misha Black Cropped Leather Jacket With Asymmetrical Front Zipper
Retailer=Mackage
Size:XXS
Size:M