私は最近、 xpath を使用して親のノード属性とその値を同時に選択する方法について質問しました。
Parent/@attr|Parent/x
親attr
の値とそのすべてx
のノードを取得します。
Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[attr] => attrValue
)
)
[1] => SimpleXMLElement Object
(
[0] => 1
)
[2] => SimpleXMLElement Object
(
[0] => 2
)
[3] => SimpleXMLElement Object
(
[0] => 3
)
)
今のこと..複数のParent
ノードがある場合、それらが混ざり合い、どれがそのノードにattr
属しているかわかりませんx
..次のような結果になります:
Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[attr] => attrValue
)
)
[1] => SimpleXMLElement Object
(
[0] => 1
)
[2] => SimpleXMLElement Object
(
[0] => 2
)
[3] => SimpleXMLElement Object
(
[0] => 3
)
[4] => SimpleXMLElement Object
(
[@attributes] => Array
(
[attr] => anotherAttrValue
)
)
[5] => SimpleXMLElement Object
(
[0] => 1
)
[6] => SimpleXMLElement Object
(
[0] => 2
)
...
)
ご覧のとおり、それらはすべて通常の結果として扱われます。私がやろうとしているのはattr
、すべての結果 ( 1, 2, 3 ) を配列または何かに含めることであり、同じことが他attr
のものに行きますこのようなものになります:
Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[attr] => attrValue
)
)
Array
(
[0] => SimpleXMLElement Object
(
[0] => 1
)
[1] => SimpleXMLElement Object
(
[0] => 2
)
[2] => SimpleXMLElement Object
(
[0] => 3
)
)
[1] => SimpleXMLElement Object
(
[@attributes] => Array
(
[attr] => anotherAttrValue
)
)
Array
(
[0] => SimpleXMLElement Object
(
[0] => 1
)
[1] => SimpleXMLElement Object
(
[0] => 2
)
[2] => SimpleXMLElement Object
(
[0] => 3
)
)
)
xpathと最初に与えられた方法を使用して