Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find the root elements name using xpath

Tags:

xml

xpath

mule

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

like image 703
Satheesh Kumar Avatar asked Feb 24 '15 03:02

Satheesh Kumar


People also ask

How do I get the XPath name of an 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.

How do I find the root node in XPath?

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.

What is XPath in JavaScript?

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.

What is relative XPath in XPath?

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.


2 Answers

This should work.

name(/*)

sample XML

<the>
    <element>hello</element>
</the>

Result

the
like image 123
stringy05 Avatar answered Nov 09 '22 09:11

stringy05


in mule you can define the MEL expression as

#[xpath:name(/*)]

to retrieve the root element

like image 38
Mohan Avatar answered Nov 09 '22 09:11

Mohan