Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the parent node name of the current node?

Tags:

what's the right syntax to get the current node's parent node's name? I know it's about the AxisName parent but what's the right syntax? for example of the following xml

<netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="file:/dev/null" iosp="lasp.tss.iosp.ValueGeneratorIOSP" start="0" increment="1">     <attribute name="title" value="Vector time series"/>     <dimension name="time" length="100"/>     <variable name="time" shape="time" type="double">         <attribute name="units" type="String" value="seconds since 1970-01-01T00:00"/>     </variable>     <group name="Vector" tsdsType="Structure" shape="time">         <variable name="x" shape="time" type="double"/>         <variable name="y" shape="time" type="double"/>         <variable name="z" shape="time" type="double"/>     </group> </netcdf> 

for the element variable I should get netcdf or group. Thanks in advance.

like image 944
user851380 Avatar asked Aug 11 '11 08:08

user851380


People also ask

How do I get parent node name?

To get the parent node name and other properties of an HTML element, we can use the . parentNode attribute. Every html element has parentNode attribute that holds the data of the parent node.

How can I get parent node in XPath?

Hey Hemant, we can use the double dot (“..”) to access the parent of any node using the XPath. For example – The locator //span[@id=”first”]/.. will return the parent of the span element matching id value as 'first.

What is the parent node?

A Node that is the parent of the current node. The parent of an element is an Element node, a Document node, or a DocumentFragment node.


1 Answers

Use:

name(..) 

The .. abbreviation is a shorthand for parent::node().

Do note: Not every parent has a name. For example the document node (/) is the parent of the top element (/*) of the document and has no name.

like image 160
Dimitre Novatchev Avatar answered Sep 17 '22 17:09

Dimitre Novatchev