Is using a wildcard in an XML path for a flow condition possible?

Post Reply
jasonx
Member
Posts: 28
Joined: Wed Jul 03, 2019 3:03 pm

Is using a wildcard in an XML path for a flow condition possible?

Post by jasonx »

Hey Everyone,

I have an XML dataset with operations. I need to search the operations to see if a step is present. My current issue is that the position of this XML element can move based on the job types.

My current build path is:

Code: Select all

[Metadata.Text:Path="/Job/Operations/Operation[1]/Name",Dataset="Xml",Model="XML",Search="Eyelet"]
I would like something like

Code: Select all

[Metadata.Text:Path="/Job/Operations/Operation[*]/Name",Dataset="Xml",Model="XML",Search="Eyelet"]
At the moment my solution is to use a bunch of OR statements and do like the following:

Code: Select all

[Metadata.Text:Path="/Job/Operations/Operation[1]/Name",Dataset="Xml",Model="XML",Search="Eyelet"] OR
[Metadata.Text:Path="/Job/Operations/Operation[2]/Name",Dataset="Xml",Model="XML",Search="Eyelet"] OR
[Metadata.Text:Path="/Job/Operations/Operation[3]/Name",Dataset="Xml",Model="XML",Search="Eyelet"] OR
etc
which isn't elegant.

I could also build a nodejs script to traverse the XML node at /Job/Operations/Operation and search and simply return a true or false to go to the next step in the flow and set the value as private data.
r.zegwaard
Member
Posts: 93
Joined: Fri Jul 08, 2011 10:31 am
Location: The Netherlands

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by r.zegwaard »

Hi

If you do it like this,

Code: Select all

[Metadata.Text:Path="//Operation[1]/Name",Dataset="Xml",Model="XML",Search="Eyelet"]
then it should find the first Operation/Name, no matter where in the XML.


Robert
laurentd
Member
Posts: 137
Joined: Wed Mar 13, 2019 2:06 pm

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by laurentd »

Use Metadata.TextIndexed, it will return you all Name values in one go.
[Metadata.TextIndexed:Path="/Job/Operations/Operation/Name",Dataset="Xml",Model="XML"]
Then use a condition to check if it contains the string you want.
Laurent De Wilde, Solution Architect @ Enfocus
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by freddyp »

Different approach: instead of selecting nodes by their index, you can also select them based on certain children elements and/or attributes. So instead of writing

Code: Select all

/Job/Operations/Operation[1]/Name
you can write

Code: Select all

/Job/Operations/Operation[Name='Eyelet']/Name
Note the single quotes! Double quotes are allowed in XPath but because the XPath is enclosed in the double quotes of the Switch variable you must use singles quotes here.

If the node does not exist, the value of that XPath in Switch will be empty so you can check for the result of that XPath not being empty: use the operator "Matches" with .+ as the right-hand value.
jasonx
Member
Posts: 28
Joined: Wed Jul 03, 2019 3:03 pm

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by jasonx »

Hey Robert the position is not always [1]. It varies job to job.
jasonx
Member
Posts: 28
Joined: Wed Jul 03, 2019 3:03 pm

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by jasonx »

Lauren your solution worked.
jasonx
Member
Posts: 28
Joined: Wed Jul 03, 2019 3:03 pm

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by jasonx »

freddyp: The XML data in that node isn't always eyelet there's a range of methods but they all contain eyelet. This step in my flow is to inject an automated note about how many eyelets etc are required for a job into our MIS system. I need to be able to search all nodes for eyelet in this instance then retrieve the data from this node. Laurens solutions solve that issue for me.
freddyp
Advanced member
Posts: 1008
Joined: Thu Feb 09, 2012 3:53 pm

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by freddyp »

I had no doubts that Laurent's solution would work, his solutions always do :D. I just suggested an alternative based on XPath to draw the forum users' attention to the potential of XPath. I think that many of you can benefit from getting to know it a bit better. To refine that previous XPath a bit further just to illustrate that (I hope it is self-explanatory):

Code: Select all

/Job/Operations/Operation[contains(Name, 'Eyelet') or contains(AnotherNode, 'Grommet')]/Name
jasonx
Member
Posts: 28
Joined: Wed Jul 03, 2019 3:03 pm

Re: Is using a wildcard in an XML path for a flow condition possible?

Post by jasonx »

Thanks freddyp,

Before I read your reply I did more reading on Xpath and came up with:

Code: Select all

[Metadata.TextIndexed:Path="/Job/Operations/Operation/Name[contains(text(),'Eyelet')]",Dataset="Xml",Model="XML"]
Based on what you suggested earlier. This is so I can search for the node and also get its value at the next step. I wasn't suggesting what you said was wrong I just didn't have the knowledge with Xpath. But you've brought this to my attention for something to learn further.

I hope I can gain more knowledge and pay it forward in the future.
Post Reply