问题是这样的,这是XML<?xml version="1.0"?>
<note
xmlns="http://www.w3school.com.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn file:///D:/_dev_stu/xsdtest/src/note.xml"> <to>George</to>
<from>John</from>
<heading name="xixi">
<subheading>hehe</subheading>
<body>Don't forget the meeting this weekend!</body>
</note>我有一个List,里面是to,from,heading,subheading,body
,存的都是这个xml里面可能有的值的名称。
我想写个方法,遍历这个List,将里面的值与xml里面的值一一匹配,找到他们的值,比如先是to,那希望获得的是George;比如遍历到name,那希望获得xixi;比如subheading,获得hehe。
我现在的做法是遇到to,就遍历整个xml,然后匹配,遇到from,就遍历所有xml,然后匹配。
想知道,有没有Dom4j或者其他包,有这种方法,就是给一个名称,然后自己搜索整个xml,有则返回值,没有就返回null之类的,类似于
String search(nodeName/AttributeName),返回这个节点的value或这个属性的值呢?请大家帮忙~\(≧▽≦)/~啦啦啦
<note
xmlns="http://www.w3school.com.cn"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com.cn file:///D:/_dev_stu/xsdtest/src/note.xml"> <to>George</to>
<from>John</from>
<heading name="xixi">
<subheading>hehe</subheading>
<body>Don't forget the meeting this weekend!</body>
</note>我有一个List,里面是to,from,heading,subheading,body
,存的都是这个xml里面可能有的值的名称。
我想写个方法,遍历这个List,将里面的值与xml里面的值一一匹配,找到他们的值,比如先是to,那希望获得的是George;比如遍历到name,那希望获得xixi;比如subheading,获得hehe。
我现在的做法是遇到to,就遍历整个xml,然后匹配,遇到from,就遍历所有xml,然后匹配。
想知道,有没有Dom4j或者其他包,有这种方法,就是给一个名称,然后自己搜索整个xml,有则返回值,没有就返回null之类的,类似于
String search(nodeName/AttributeName),返回这个节点的value或这个属性的值呢?请大家帮忙~\(≧▽≦)/~啦啦啦
解决方案 »
- servlet接口中init()方法没有方法体,系统调用它干什么
- Hibernate: insert into project 成功但数据库表中没有数据
- 一个超级简单的Spring注入的问题,为什么说找不到property? 内详...
- 急!!Hibernate查询出来的数据与数据库中的不一样???!!!
- 为什么jsp显示不了背景图片啊?
- tomcat在退出的时候如何能做一些清理动
- spring有什么好书吗
- [400分]CMP在部署的时候出错误,请帮忙,十分紧急,求大家帮忙
- 高分求助----如何配置(JBoss+Tomcat协同工作配置,与开发工具的集成),分数不够,继续追加!!!
- java程序性能测试发现执行时间很奇怪
- jsp小问题求教
- <img> 标签图片不刷新之疑惑
//to/text()
//from/text()
<note1 ....>
....
<to> George1 </to>
......
</note1>
<note2 ....>
....
<to> George2 </to>
......
</note2>
Document 不是有 selectNodes/selectSingleNode 方法吗?