在 PHP4 中对 XML 数据进行排序
您好,我有以下 XML 代码:
<?xml version="1.0" encoding="UTF-8"?>
<connector_ret>
<function name="search">
<row id="1">
<col id="1">AAA</col>
<col id="2">243168</col>
<col id="3">090828-000300</col>
<col id="4">Subject</col>
</row>
<row id="2">
<col id="1">BBB</col>
<col id="2">243515</col>
<col id="3">090831-000116</col>
<col id="4">Subject</col>
</row>
<row id="3">
<col id="1">BBB</col>
<col id="2">244913</col>
<col id="3">090905-000022</col>
<col id="4">Subject</col>
</row>
<row id="4">
<col id="1">CCC</col>
<col id="2">245323</col>
<col id="3">090907-000253</col>
<col id="4">Subject</col>
</row>
<row id="5">
<col id="1">CCC</col>
<col id="2">245323</col>
<col id="3">090907-000253</col>
<col id="4">Subject</col>
</row>
</function>
</connector_ret>
我想知道是否可以在 PHP4 中循环此代码,并在给定变量时仅显示某些行。
例如,如果给定的变量是 BBB,则仅显示第一列 id 也等于 BBB 的行。
因此输出将是:
BBB - 243515 - 090831-000116 - 主题 BBB - 244913 - 090905-000022 - 主题
和其他行将被忽略。
如果给定的变量是 AAA,则输出将为:
AAA - 243168 - 090828-000300 - 主题
您明白了:)
如果您能提供帮助,那就太棒了。非常感谢。
Hi there I have the following XML code:
<?xml version="1.0" encoding="UTF-8"?>
<connector_ret>
<function name="search">
<row id="1">
<col id="1">AAA</col>
<col id="2">243168</col>
<col id="3">090828-000300</col>
<col id="4">Subject</col>
</row>
<row id="2">
<col id="1">BBB</col>
<col id="2">243515</col>
<col id="3">090831-000116</col>
<col id="4">Subject</col>
</row>
<row id="3">
<col id="1">BBB</col>
<col id="2">244913</col>
<col id="3">090905-000022</col>
<col id="4">Subject</col>
</row>
<row id="4">
<col id="1">CCC</col>
<col id="2">245323</col>
<col id="3">090907-000253</col>
<col id="4">Subject</col>
</row>
<row id="5">
<col id="1">CCC</col>
<col id="2">245323</col>
<col id="3">090907-000253</col>
<col id="4">Subject</col>
</row>
</function>
</connector_ret>
I was wondering if it was possible to loop through this in PHP4 and only display certain rows when given a variable.
For example if the variable given is BBB then only display rows where the first column id is also equal to BBB.
So the output would be:
BBB - 243515 - 090831-000116 - Subject
BBB - 244913 - 090905-000022 - Subject
and the other rows are just ignored.
If the variable given is AAA the output would be:
AAA - 243168 - 090828-000300 - Subject
You get the idea :)
If you can help that'd be fantastic. Thanks so much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你应该使用
xpath
来进行这样的处理you should use
xpath
to do such processing您可以将 XSL-T 作为解决方案。选择所需的节点并转换结果非常容易。
You might look at XSL-T as your solution to this. It's easy enough to select the nodes you want and transform the results.