Php以xml检索某些信息 [英] Php retrieve certain information in xml

查看:75
本文介绍了Php以xml检索某些信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的xml文件:

I have a xml file like this:

<?xml version="1.0" encoding="UTF-8"?>
<version_logs>
	<version_log id="0.8.351.639">
		<version>0.8.351.639</version>
		<release_date>May 2014</release_date>
		<logs>
			<log>Minor bug fixes</log>
			<log>Increase compatibility</log>
			<log>Better user</log>
			<log>New languages</log>
		</logs>
	</version_log>
	<version_log id="5454.54.464.3">
		<version>5454.54.464.3</version>
		<logs>
			<log>fffff</log>
			<log>fdgdgsdgsdgsd</log>
			<log>ererererer</log>
			<log>lllllll</log>
			<log>lllllll</log>
			<log>lllllll</log>
			<log>lllllll</log>
		</logs>
	</version_log>
</version_logs>





我试图通过它的id来获取version_log标签的所有信息。使用类似的东西:



I am trying to get all the information of the version_log tag by it's "id". By using something like this:

$nodes = $xml->xpath('//version_log/version[contains(., "5454.54.464.3")]');





哪个只给我版本标签值而不是其他信息。



我在这里缺少什么?



Which only give me the version tag value and not the rest of the information.

What I am missing here?

推荐答案

节点 =
nodes =


xml-> xpath(' // version_log / version [contains(。,5454.54.464.3)]');
xml->xpath('//version_log/version[contains(., "5454.54.464.3")]');





哪个只给我版本标签值而不是其他信息。



我在这里缺少什么?



Which only give me the version tag value and not the rest of the information.

What I am missing here?


只是合乎逻辑。您只收到该版本,因为这正是您在查询中所要求的。根据这些词的真实含义,其余的信息应该是指整个XML,但是你已经拥有它了。 :-)



你只需要为自己制定你想要的东西。需要具有版本的节点的子节点吗?好的,请阅读此节点的子节点。等等。



-SA
Just be logical. You receive the version only because this is exactly what your requested in your query. "The rest on information", by the true meaning of these words, should mean the whole XML, but you already have it. :-)

You just need to formulate what you want at lest for yourself. Need the child nodes of the node with the version? Okay, read the children of this node. And so on.

—SA


这篇关于Php以xml检索某些信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆