dom4j解析,大佬求指教?

qq_38720454 2018-06-13 09:52:30
<?xml version="1.0" encoding="UTF-8"?>
<pages>
<page keyword = "注册页">
<locator keyword = "手机号码输入框" by = "id" value = "mobilephone"></locator>
<locator keyword = "密码输入框" by = "id" value = "password"></locator>
<locator keyword = "重复密码输入框" by = "id" value = "pwdconfirm"></locator>
<locator keyword = "注册按钮" by = "id" value = "signup-button"></locator>
<locator keyword = "错误提示元素" by = "xpath" value = "//p{@class='tips'}"></locator>
</page>
<page keyword = "登录页">
<locator keyword = "手机号码输入框" by = "id" value = "mobilephone"></locator>
<locator keyword = "密码输入框" by = "id" value = "password"></locator>
<locator keyword = "登录按钮" by = "id" value = "signup-button"></locator>
<locator keyword = "错误提示元素" by = "id" value = "//p{@class='tips'}"></locator>
</page>
</pages>
...全文
690 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
stacksoverflow 2018-06-18
  • 打赏
  • 举报
回复
照着上面的改一改,比如加上错误处理什么的。
stacksoverflow 2018-06-18
  • 打赏
  • 举报
回复
package test; import java.io.File; import org.dom4j.Document; import org.dom4j.Element; import org.dom4j.io.SAXReader; public class Dom4JSample { public static void main(String[] args) throws Exception{ SAXReader saxReader = new SAXReader(); Document document = saxReader.read(new File("c:/temp/test.xml")); Element el_pages = document.getRootElement(); for(Element el_page:el_pages.elements()) { String attr_page_keyword = el_page.attribute("keyword").getText(); System.out.println("page_keyword:"+attr_page_keyword); for(Element el_locator:el_page.elements()) { String attr_locator_keyword = el_locator.attribute("keyword").getText(); String attr_locator_by = el_locator.attribute("by").getText(); String attr_locator_value = el_locator.attribute("value").getText(); System.out.println("locator_keyword:"+attr_locator_keyword); System.out.println("locator_by:"+attr_locator_by); System.out.println("locator_value:"+attr_locator_value); } } } }
verejava 2018-06-17
  • 打赏
  • 举报
回复

23,404

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧