0

I'm new to python, I'm using xml.etree.elementtree module to parse the xml file. while parsing trying to get the xml element path which is having the value.

for example:

<root>
  <a>
     <b>Hello</b>
     <b1>Hi</b1>
  </a>
  <c>
    <d>Welcome</d>
    <e>Sample xml</e>
  </c>
</root>

here I want to get the element path, which is having value

root/a/b
root/a/b1
root/c/d
root/c/e

like in lxml module we can get it with the help of getelement(). But, how can we achieve the same by using the module xml.etree.elementtree.

Esakki Thangam
  • 355
  • 2
  • 7
  • you can use `iter()` on root and see which tags have values – Bijay Regmi Sep 20 '22 at 20:32
  • lxml has no method called `getelement()`. I think you mean `getelementpath()` or `getpath()`. https://lxml.de/api/lxml.etree._ElementTree-class.html – mzjn Sep 21 '22 at 05:40
  • This question looks like a duplicate of https://stackoverflow.com/q/68215347/407651 – mzjn Sep 21 '22 at 06:01

0 Answers0