ddd aaa bbb
如何选取 aaa 的值哇!!
1
imn1 2016-10-20 15:51:01 +08:00
不能,正则吧
|
2
Spectre OP @imn1 好像上面没显示出来 是这种<span></span>aaa<span></span> 我要获取 aaa 的值
|
3
imn1 2016-10-20 16:10:08 +08:00
/xpath/text()
|
4
hw20686832 2016-10-20 16:12:23 +08:00
xpath2.0 有个 tokenize 方法,类似于 Python 的 split
|
5
argsno 2016-10-20 16:15:47 +08:00
text()
|
6
anguskwan 2016-10-20 16:20:57 +08:00
楼主要取 xml 里的第二个孩子,还是 text 里第二列?
|
7
cuebyte 2016-10-20 16:28:12 +08:00
text() 取出来自己做个 split(' ')[1] 啊
|
8
Honwhy 2016-10-20 16:28:40 +08:00
```
NodeList spanNode = (NodeList) xpath.evaluate("/widgets/widget[3]/node()", inputSource, XPathConstants.NODESET); for(int i = 0; i < spanNode.getLength(); i++) { Node node = spanNode.item(i); if(node.getNodeType() == Node.TEXT_NODE) { System.out.println(spanNode.item(i).getTextContent()); } } ``` ``` <?xml version="1.0" encoding="UTF-8" ?> <widgets xmlns:prefix="http://www.eclipse.org/birt/2005/design"> <widget> <manufacturer/> <dimensions/> </widget> <widget> <manufacturer/> <dimensions>101</dimensions> <attr1 name="honey">10333</attr1> </widget> <widget> <span>bbb</span> aaa <span>ccc</span> </widget> </widgets> ``` |
9
dsg001 2016-10-21 21:22:22 +08:00
dom 操作用 xpath , text 操作用 re
|