Skip to content
Advertisement

xml.etree.ElementTree get node depth

The XML:

JavaScript

The code:

JavaScript

The output:

JavaScript

The Xml represents a tree like structure of a sitemap.

I have been up and down the docs and Google all day and can’t figure it out hot to get the node depth of entries.

I used counting of the children container but that only works for the first parent and then it breaks as I can’t figure it out how to reset. But this is probably just a hackish idea.

The desired output:

JavaScript

Advertisement

Answer

Used lxml.html.

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement