<Result usetabdocview='false' method='Login'><Reason code='0' />
<PersonInfo>
<name>小红</name>
</PersonInfo>
<MenuItems>
<Item id='Jobstodo' count='3' desc='待办' show='0'>待办</Item>
<Item id='Jobsdoing' count='0' desc='在办' show='0'>在办</Item>
<Item id='Joby' count='154' desc='历史' show='0'>历史</Item>
<Item id='Adver' count='0' desc='信息' show='0'>信息</Item>
<Item id='earch' count='154' desc='文件' show='0'>文件</Item>
</MenuItems>
</Result>
找了好多资料,但是都不能实现
1、DOM解析;2、SAX解析;3、JDOM解析;4、DOM4J解析
获取result使用getelementname方法应该可以得到,上面四个应该都有类似的方法,大同小异
获取usetabdocview应该先获取节点属性,使用element.getattribute
然后获取属性名字,attribute.getname应该也有类似的方法的
DOM4J解析
SAXReader reader = new SAXReader();
File xmlFile = new File("test.xml");
Document doc = reader.read(xmlFile);
//获取根元素
Element root = doc.getRootElement();
Element result = root.element("Result");
Attribute attr1 = result.attribute("usetabdocview");
//以此类推,也可以用Iterator迭代器遍历元素
可以使用模板引擎,先定义好一个模板,然后进行模板解析,可以去看看Beetl,挺不错的