【发布时间】:2011-09-26 18:38:09
【问题描述】:
我有以下 SimpleXML 对象:
SimpleXMLElement Object
(
[@attributes] => Array
(
[status] => ok
)
[a] => SimpleXMLElement Object
(
[b] => Array
(
[0] => SimpleXMLElement Object
(
[c] => Google
[d] => GOOG
[e] => http://www.google.com
)
[1] => SimpleXMLElement Object
(
[c] => Yahoo
[d] => YHOO
[e] => http://www.yahoo.com
)
[2] => SimpleXMLElement Object
(
[c] => Microsoft
[d] => MSFT
[e] => http://www.microsoft.com
)
鉴于d 我想得到e - 由于b 是一个数组,有没有办法在不循环整个数组的情况下做到这一点?
<stk status="ok">
<a>
<b>
<c>Yahoo</c>
<d>YHOO</d>
<e>http://www.yahoo.com</e>
</b>
<b>
<c>Google</c>
<d>GOOG</d>
<e>http://www.google.com</e>
</b>
<b>
<c>Microsoft</c>
<d>MSFT</d>
<e>http://www.microsoft.com</e>
</b>
</a>
</stk>
【问题讨论】:
-
XPath:
//d/following-sibling::e[1]? -
关闭!这实际上是返回所有
e值。我怎样才能让它返回e的值,其中d是,让天,YHOO? -
如果你愿意分享底层的 XML,那就更容易分辨了。
-
更新帖子以显示底层 XML。