Skip to main content
December 19, 2024
Question

How to retrieve X path(not the value) from an XML file.

  • December 19, 2024
  • 3 replies
  • 0 views

Hi people,

I have requirement where i need to find the X path of an XML file. We have functions to retrieve a value using the X path. But our requirement is retrieve the X path instead of the value, So that the user will use that and cross verify the xml file whether its matching. Here is an example.

Input:

<Document>
<customer>
<details>
<name>xyz</name>
<address>abc</address>
<contact>
<phone>45667778</phone>
<employee>
<company>
<department>
<id>6786</id>
</department>
</company>
</employee>
</contact>
</details>

</customer>
</Document>


Output:

for Retrieving the name XYZ this would be the X path

"<Document><customer><details><name>" this is actual output we require

And this is the output we need for nested X path.

"<Document><customer><details> <contact><employee><company><department><id>"

3 replies

stefanhelzle0001
December 19, 2024

The whole idea of xPath is, no know the path where to look for data beforehand. If you do not know the structure of the XML, I do not know of any easy way to somehow find specific nodes, values, or paths in it.

December 19, 2024

Is there any built-in function or third party plug-in which might be of any help in this case.
The structure of the XML is dynamic in nature, hence the issue.

mathieud0001
December 19, 2024