simplexml 路径(按索引)
我正在解析 simplexml,通常我的简单 xml 看起来像这样,
$sig_size = (int)$xmlObject->sig->points;
在这个例子中返回 24
<?xml version='1.0' standalone='yes'?>
<photo id='470'>
<artist>mg</artist>
<lines>
<points>22</points>
<angle>-5</angle>
<x>165</x>
<align>center</align>
<color>ffffff</color>
</lines>
<sig>
<padding>35</padding>
<x>175</x>
<y>300</y>
<points>24</points>
<angle>-5</angle>
<align>center</align>
<color>ffffff</color>
</sig>
</photo>
现在我想添加第二个 sig 项并通过索引引用它,所以 xml 看起来像这样
<?xml version='1.0' standalone='yes'?>
<photo id='470'>
<artist>mg</artist>
<lines>
<points>22</points>
<angle>-5</angle>
<x>165</x>
<align>center</align>
<color>ffffff</color>
</lines>
<sig>
<padding>35</padding>
<x>175</x>
<y>300</y>
<points>24</points>
<angle>-5</angle>
<align>center</align>
<color>ffffff</color>
</sig>
<sig>
<padding>35</padding>
<x>175</x>
<y>300</y>
<points>10</points>
<angle>-5</angle>
<align>center</align>
<color>ffffff</color>
</sig>
</photo>
,那么我如何重写php行通过索引获取它
I'm parsing simplexml and normally my simple xml would look like this
$sig_size = (int)$xmlObject->sig->points;
which returns 24 in this example
<?xml version='1.0' standalone='yes'?>
<photo id='470'>
<artist>mg</artist>
<lines>
<points>22</points>
<angle>-5</angle>
<x>165</x>
<align>center</align>
<color>ffffff</color>
</lines>
<sig>
<padding>35</padding>
<x>175</x>
<y>300</y>
<points>24</points>
<angle>-5</angle>
<align>center</align>
<color>ffffff</color>
</sig>
</photo>
now I want to add a second sig item and refeence it by the index so the xml would look like this
<?xml version='1.0' standalone='yes'?>
<photo id='470'>
<artist>mg</artist>
<lines>
<points>22</points>
<angle>-5</angle>
<x>165</x>
<align>center</align>
<color>ffffff</color>
</lines>
<sig>
<padding>35</padding>
<x>175</x>
<y>300</y>
<points>24</points>
<angle>-5</angle>
<align>center</align>
<color>ffffff</color>
</sig>
<sig>
<padding>35</padding>
<x>175</x>
<y>300</y>
<points>10</points>
<angle>-5</angle>
<align>center</align>
<color>ffffff</color>
</sig>
</photo>
so how do I re-write the php line to get it by index
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须使用括号 []:
You would have to use brackets []: