Search code examples
xmlxpathtibco

get node value by passing node name dynamically in Xpath


I am using Tibco xpath.

my inputs are like

<output>
<outputf1>123</outputf1>
<outputf2>123</outputf2>
<outputf3>123</outputf3>
<outputf4>123</outputf4>
</output>

Outputf1, outputf2 ..comes dynamically from another activity.

how to retrieve the value by passing the node name dynamically to the XML.


Solution

  • Here are two XPath functions that provide the node name. name() provides the name including a namespace prefix, local-name()the name without it. You can select all element nodes and filter them by comparing the local-name():

    /outputs/*[local-name() = 'outputf2']
    

    You can even combine that with starts-with() to select all "output" element nodes.

    /outputs/*[starts-with(local-name(), 'output')]
    

    Be careful with that - outputs starts with output, too.

    HINT: This is really bad XML. If you can change it I suggest something like <output index="f1">123</output>