我正在尝试@id
从表达式内部解析 的值,xPath
例如:
"/hrdg:data/hrdg:meeting[@code='30J7Q']/hrdg:event[@id='2545525']/hrdg:selection[@id='31192111']"
我已经编写了这个正则表达式,并且正在使用以下代码进行匹配:
Pattern selectionIdPattern = Pattern.compile(".*/hrdg:selection[@id=\'(\\d+)\'].*");
// Grab the xPath from the XML.
xPathData = // Loaded from XML..;
// Create a new matcher, using the id as the data.
Matcher matcher = selectionIdPattern.matcher(xPathData);
// Grab the first group (the id) that is loaded.
if(matcher.find())
{
selectionId = matcher.group(1);
}
但是selectionId
不包含 之后的值@id=
。
期望结果的例子
例如,通过上面的语句,我想得到:
"/hrdg:data/hrdg:meeting[@code='30J7Q']/hrdg:event[@id='2545525']/hrdg:selection[@id='31192111']"
Data I want: 31192111