如何搜索给定值的特定节点? [英] how can i search for a particular node for a given value ?

查看:70
本文介绍了如何搜索给定值的特定节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的xml格式如下:



 <  课程 >  
< 登录 > 1 < / login >
< 版本 > 1.2.3.5 < / version >
< ; course_id > 1 < / course_id >
< course_name > physics < / course_name >
< module module_id = 1 > ;
< page > 1 < / page > ;
< / module >
< module module_id = 2 >
< ; page > 12 < / page >
< ; / module >
< module module_id = 3 >
< page > 4 < / page >
< / module >
< / course >





这是我想要的:



if(a 模块节点 module_id 2 不存在



{

我的代码



}



如何找到这个节点...



i正在尝试这个..



$ value = $ row ['Module_id'];



$ ModuleValue = $ xml-> $ xpath(/ Course / Module [Module_id] ='$ value');

if($ ModuleValue == null)



{





}

解决方案

value =


row ['Module_id'];



ModuleValue =

My xml is formatted is as given below:

<course>
   <login>1</login>
   <version>1.2.3.5</version>
   <course_id>1</course_id>
   <course_name>physics</course_name>
   <module module_id="1">
          <page>1</page>
   </module>
   <module module_id="2">
          <page>12</page>
   </module>
   <module module_id="3">
          <page>4</page>
   </module>
</course>



Here is what I want:

if (a module node with module_id value 2 not exists than)

{
my code

}

how to find this node...

i was trying this ..

$value=$row['Module_id'];

$ModuleValue=$xml->$xpath("/Course/Module[Module_id]='$value'");
if($ModuleValue==null)

{


}

解决方案

value=


row['Module_id'];


ModuleValue=


这篇关于如何搜索给定值的特定节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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