有人可以发布一个示例,使用带有VTD XML解析器的union运算符(|)吗? 以下不适用于VTD XML解析器,但适用于jxpath解析器。 / a | / B
答案 0 :(得分:0)
好的,这是联合表达式的一个快速示例。
import com.ximpleware.AutoPilot;
import com.ximpleware.NavException;
import com.ximpleware.VTDException;
import com.ximpleware.VTDGen;
import com.ximpleware.VTDNav;
/**
* An issue that seems to exist in VTD-XML 2.12 and 2.13 (but not 2.11) that causes lookups for default namespace nodes
* to also pickup non-default namespaced nodes.
*/
public class VtdAutoPilotXpathIssueTest {
private static final String XML = "<a xmlns:x=\"" + "urn:test" + "\"><b id=\"1\"/><x:b id=\"2\"/><b id=\"3\"/></a>";
public static void main(String[] s) throws VTDException{
VTDGen vg = new VTDGen();
vg.setDoc(XML.getBytes());
vg.parse(false);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
ap.declareXPathNameSpace("abc", "urn:test");
ap.selectXPath("//b|/a");
int i=0;
while((i=ap.evalXPath())!=-1){
System.out.println(" token "+ vn.toRawString(i));
}
}
}