使用属性名从simplexml\u加载\u字符串中提取xml元素
我想从属性名(sm_field_base_url)或xpath上的下面提到的XML中提取使用属性名从simplexml\u加载\u字符串中提取xml元素,xml,xpath,simplexml,Xml,Xpath,Simplexml,我想从属性名(sm_field_base_url)或xpath上的下面提到的XML中提取sm_field_base_url。我怎样才能做到这一点。 我正在使用simplexml\u load\u string()解析xml 编辑:如何从以下内容中提取内容: <date name="ds_changed">2014-01-17T05:25:56Z</date> or <long name="is_uid">1</long> 2014-01-17T
sm_field_base_url
。我怎样才能做到这一点。
我正在使用simplexml\u load\u string()
解析xml
编辑:如何从以下内容中提取内容:
<date name="ds_changed">2014-01-17T05:25:56Z</date>
or
<long name="is_uid">1</long>
2014-01-17T05:25:56Z
或
1.
或
Titan Raga女式珍珠白表盘手表优惠券@Myntra或
节点/95260
或
p/titan raga女式珍珠白表盘手表myntracom手表
下面是XML:
- <response>
<result name="response" numFound="223" start="0" maxScore="1.4879669">
<doc>
<float name="score">1.4879669</float>
<bool
name="bs_promote">false</bool>
<str name="bundle_name">Product and Coupon</str>
<str name="content"> Brand: Titan Create Combination: No Product Popularity: 0 Best
Coupon Status: 0 Retailer: Myntra.com Category: Watches Best Coupon Status Display: Without Coupons Savings: INR 0 Net Price:
INR 2 700 List Price: INR 2 700
Product Name: Titan Raga Women Pearly White Dial Watch MRPProductPrice: INR 0 Best Coupon CouponCode: Base Url:
http://www.myntra.com/Watches/Titan/Titan-Raga-
Women-Pearly-White-Dial-Watch/135793/buy LastCheckedTime: Friday, January 17, 2014- 10:52 Best Coupon: </str>
<arr name="dm_field_lastcheckedtime">
<date>2014-01-
17T05:22:42Z</date>
</arr>
<date name="ds_changed">2014-01-17T05:25:56Z</date>
<long name="is_uid">1</long>
<str name="label">Titan Raga Women Pearly White Dial Watch
Coupons @ Myntra</str>
<str name="path">node/95260</str>
<str name="path_alias">p/titan-raga-women-pearly-white-dial-watch-myntracom-watches</str>
<str
name="site">http://couponvoodoo.com/</str>
<arr name="**sm_field_base_url**">
<str>http://www.myntra.com/Watches/Titan/Titan-Raga-Women-Pearly-White-Dial-
watch/135793/buy</str>
</arr>
<arr name="sm_vid_Retailer">
<str>Myntra.com</str>
</arr>
<arr name="spell">
<str>Titan Raga Women Pearly White Dial Watch Coupons @
Myntra</str>
<str> Brand: Titan Create Combination: No Product Popularity: 0 Best Coupon Status: 0 Retailer: Myntra.com Category:
Watches Best Coupon Status
Display: Without Coupons Savings: INR 0 Net Price: INR 2 700 List Price: INR 2 700 Product Name: Titan Raga Women Pearly White
Dial Watch MRPProductPrice: INR 0
Best Coupon CouponCode: Base Url: http://www.myntra.com/Watches/Titan/Titan-Raga-Women-Pearly-White-Dial-Watch/135793/buy
LastCheckedTime: Friday, January 17, 2014-
10:52 Best Coupon: </str>
<str>Titan</str>
<str>Myntra.com</str>
<str>Watches Women</str>
</arr>
<str name="ss_language">und</str>
<str name="ss_name">admin</str>
<str
name="ss_name_formatted">admin</str>
<str name="teaser"> Brand: Titan Create Combination: No Product Popularity: 0 Best Coupon Status: 0 Retailer: Myntra.com
Category: Watches Best Coupon Status Display: Without Coupons Savings: INR 0 Net Price: INR 2 700 List Price: INR 2 700 Product
Name: Titan Raga Women Pearly
White Dial Watch</str>
<arr name="tid">
<long>7979</long>
<long>8</long>
<long>62</long>
<long>46</long>
</arr>
<date name="timestamp">2014-01-29T05:52:45.478Z</date>
<arr
name="tm_vid_2_names">
<str>Myntra.com</str>
</arr>
<arr name="tm_vid_3_names">
<str>Watches Women</str>
</arr>
<arr name="tm_vid_4_names">
<str>Titan</str>
</arr>
<str
name="tos_name">admin</str>
<str name="tos_name_formatted">admin</str>
<str name="url">http://couponvoodoo.com/p/titan-raga-women-pearly-white-dial-watch-myntracom-
watches</str>
</doc>
</result>
</response>
-
1.4879669
假的
产品及优惠券
品牌:Titan Create组合:无产品知名度:0最佳
优惠券状态:0零售商:Myntra.com类别:手表最佳优惠券状态显示:无优惠券节省:INR 0净价:
2700卢比标价:2700卢比
产品名称:Titan Raga女式珍珠白表盘手表MRP产品价格:INR 0最佳优惠券耦合代码:基本Url:
http://www.myntra.com/Watches/Titan/Titan-Raga-
女式珍珠白表盘表/135793/购买最新支票时间:2014年1月17日星期五-10:52最佳优惠券:
2014-01-
17T05:22:42Z
2014-01-17T05:25:56Z
1.
Titan Raga女式珍珠白色表盘表
Myntra的优惠券
节点/95260
p/titan raga女式珍珠白表盘手表myntracom手表
http://couponvoodoo.com/
http://www.myntra.com/Watches/Titan/Titan-Raga-Women-Pearly-White-Dial-
手表/135793/购买
Myntra.com
Titan Raga女式珍珠白色表盘手表优惠券@
明特拉
品牌:Titan创建组合:无产品知名度:0最佳优惠券状态:0零售商:Myntra.com类别:
手表最佳优惠券状态
展示:无优惠券优惠:0卢比净价:2700卢比标价:2700卢比产品名称:Titan Raga女式珍珠白
表盘手表MRP产品价格:卢比0
最佳优惠券耦合代码:基本Url:http://www.myntra.com/Watches/Titan/Titan-Raga-Women-Pearly-White-Dial-Watch/135793/buy
上次检查时间:2014年1月17日星期五-
10:52最佳优惠券:
泰坦
Myntra.com
看女人
und
管理
管理
品牌:Titan Create组合:无产品知名度:0最佳优惠券状态:0零售商:Myntra.com
类别:手表最佳优惠券状态显示:无优惠券节约:卢比0净价:卢比2700标价:卢比2700产品
姓名:Titan Raga女式珍珠
白色表盘表
7979
8.
62
46
2014-01-29T05:52:45.478Z
Myntra.com
看女人
泰坦
管理
管理
http://couponvoodoo.com/p/titan-raga-women-pearly-white-dial-watch-myntracom-
监视
以下xpath表达式
$results = $xml->xpath("//arr[@name = 'sm_field_base_url']/str");
将选择具有该名称属性的所有
节点,并返回其子节点
$results
将是一个对象数组
。要将结果保存为字符串
,请执行以下操作:
$results = array_map('strval', $results);
感谢sryy迟来的回复,并感谢它的有效性。您还可以帮助我理解如何从
1
@user2129794//long[@name='is_uid']]提取1
应该可以做到这一点。很高兴我能帮上忙,请考虑一下我的答案,点击左边的记号。