Thursday, 6 November 2014

Look for a defined sequence-pattern in XML



I am thinking about how/if XQuery can be used to check whether a specific pattern exists in a XML file.


Example: Think of a (simplified) XML representing a process flow (StartEvent > UserTask > AutoTask > EndEvent).



<process>
<startEvent id="start1">
<outgoing>flow1</outgoing>
</startEvent>

<userTask id="user1">
<incoming>flow1</incoming>
<outgoing>flow2</outgoing>
</userTask>

<autoTask id="auto1">
<incoming>flow2</incoming>
<outgoing>flow3</outgoing>
</autoTask>

<endEvent id="end1">
<incoming>flow3</incoming>
</endEvent>
<flow id="flow1" source="start1" target="user1"/>
<flow id="flow2" source="user1" target="auto1"/>
<flow id="flow3" source="auto1" target="end1"/>
</process>


Now I want to check whether somewhere in the file is an element of type "userTask" which is immediately followed by an element of type "autoTask". Please note that this sequence needs to be checked by going along the incoming/outgoing flow definitions and cannot be derived from the ordering in the document.


Is there any way to do this with xquery?


Thanks in advance for your ideas!


No comments:

Post a Comment