XPath表达式在Saxon9中不起作用

时间:2018-06-08 08:07:13

标签: xml xpath saxon

我使用Saxon 9-HE来评估XPath表达式,详情如下:

XML:

componentDidUpdate

守则: 公共类XPathTest {

        <?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/test">
  <process id="myProcess" name="My process" isExecutable="true">
    <startEvent id="startevent_100" name="Start_this"></startEvent>
    <endEvent id="endevent1" name="End"></endEvent>
    <userTask id="usertask1" name="UserTask1" activiti:formKey="ThisIsTheFormKey_identifier"></userTask>
    <sequenceFlow id="flow3" sourceRef="usertask1" targetRef="endevent1">   </sequenceFlow>
<userTask id="usertask2" name="UserTask0"></userTask>
<sequenceFlow id="flow4" sourceRef="startevent_100" targetRef="usertask2"></sequenceFlow>
<sequenceFlow id="flow5" sourceRef="usertask2" targetRef="usertask1"></sequenceFlow>
  </process>
  <bpmndi:BPMNDiagram id="BPMNDiagram_myProcess">
<bpmndi:BPMNPlane bpmnElement="myProcess" id="BPMNPlane_myProcess">
  <bpmndi:BPMNShape bpmnElement="startevent_100" id="BPMNShape_startevent_100">
    <omgdc:Bounds height="35.0" width="35.0" x="130.0" y="90.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="endevent1" id="BPMNShape_endevent1">
    <omgdc:Bounds height="35.0" width="35.0" x="610.0" y="90.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="usertask1" id="BPMNShape_usertask1">
    <omgdc:Bounds height="55.0" width="105.0" x="440.0" y="80.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNShape bpmnElement="usertask2" id="BPMNShape_usertask2">
    <omgdc:Bounds height="55.0" width="105.0" x="230.0" y="80.0"></omgdc:Bounds>
  </bpmndi:BPMNShape>
  <bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
    <omgdi:waypoint x="545.0" y="107.0"></omgdi:waypoint>
    <omgdi:waypoint x="610.0" y="107.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
    <omgdi:waypoint x="165.0" y="107.0"></omgdi:waypoint>
    <omgdi:waypoint x="230.0" y="107.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
  <bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
    <omgdi:waypoint x="335.0" y="107.0"></omgdi:waypoint>
    <omgdi:waypoint x="440.0" y="107.0"></omgdi:waypoint>
  </bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
  </bpmndi:BPMNDiagram>
</definitions>

没有输出,没有选择节点。另一方面,如果我使用这个XPath:

public static void main(String[] args) throws Exception{

    String xmlFileName="D:\\workspaces\\general\\TestActivity\\TestProcess.bpmn";
    String xPathExpression="/child::definitions/child::process";

    Processor xPathProcessor=new Processor(false);
    XPathCompiler xPathCompiler=xPathProcessor.newXPathCompiler();
    DocumentBuilder documentBuilder=xPathProcessor.newDocumentBuilder();
    StreamSource source=new StreamSource(new FileInputStream(xmlFileName));
    XdmValue document=documentBuilder.build(source);

    XPathExecutable compiledXPath=xPathCompiler.compile(xPathExpression);
    XPathSelector selector=compiledXPath.load();
    selector.setContextItem(document.itemAt(0));

    System.out.println(selector.evaluate());

}

}

我正在获取'process'元素。不知道为什么会这样。

我在这里试过freeformatter.com。我得到了所需的输出(参见下图)。 XPath基本上是正确的,我错过了什么吗?

任何帮助都将不胜感激。

enter image description here

0 个答案:

没有答案