为什么我的代码无法正确解析此 XML 文件?
我正在尝试用 PHP 解析 xml 日志文件。它具有以下结构
<log>
<logentry revision="1745">
<author>abc</author>
<date>2010-08-31T20:46:29.691125Z</date>
<paths>
<path kind="" action="M">/trunk/myserver/abc.java</path>
<path kind="" action="M">/trunk/myserver/test.java</path>
<path kind="" action="M">/trunk/myserver/xmltest.java</path>
</paths>
<msg>how to make it work!</msg>
</logentry>
</log>
我怎样才能从这个 xml 文件中提取所有数据?如何循环日志文件以提取所有数据?我也想从行动中得到那个M。
我也尝试了这段代码,但无法使其适用于整个文件。
$xml = simplexml_load_file("test.log");
echo $xml->getName();
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
I am trying to parse an xml log file in PHP. It has following structure
<log>
<logentry revision="1745">
<author>abc</author>
<date>2010-08-31T20:46:29.691125Z</date>
<paths>
<path kind="" action="M">/trunk/myserver/abc.java</path>
<path kind="" action="M">/trunk/myserver/test.java</path>
<path kind="" action="M">/trunk/myserver/xmltest.java</path>
</paths>
<msg>how to make it work!</msg>
</logentry>
</log>
How can I extract all data from this xml file? How can loop on log file to extract all data? I want to get that M from action as well.
I tried this code as well, but I couldn't make it work for whole file.
$xml = simplexml_load_file("test.log");
echo $xml->getName();
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
simplexml
来实现此目的you can use
simplexml
for that purpose使用 PHP 的 DOMDocument 类。
Use PHP's DOMDocument class.