Hi am having an XML file I have to find the root element of it using xpath am using mule ESB so I need to set this root element as variable so anyone can provide me xpath for finding the name of the root element
Use the XPath name () function. One XPath expression to obtain the name of the top (not root!) element is: The name () function returns the fully-qualified name of the node, so for an element <bar:foo/> the string "bar:foo" will be returned.
XPath - Root Node. Following are the ways to get root element and do the processing afterwards. Use Wildcard. Use /* , wild card expression to select the root node. Use Name. Use /class, to select root node by name. Use Name with wild card. Use /class/*, select all element under root node.
The key characteristic of XPath is that it begins with the single forward slash (/) ,which means you can select the element from the root node. Below is the example of an absolute xpath expression of the element shown in the below screen.
Relative XPath . The key characteristic of XPath is that it begins with the single forward slash (/) ,which means you can select the element from the root node. Below is the example of an absolute xpath expression of the element shown in the below screen.
This should work.
name(/*)
sample XML
<the>
<element>hello</element>
</the>
Result
the
in mule you can define the MEL expression as
#[xpath:name(/*)]
to retrieve the root element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With