0

Having the following xml,

<markets xmlns:cap="URI">
    <us>
        <summary>
            <index>NASDAQ</index>
            <last>34,000</last>
            <cap:change>-2.4</cap:change>
        </summary>
    </us>
</markets>

Let's assume I've an Element that points to NASDAQ,

import xml.etree.ElementTree as ET
markets = ET.parse('markets.xml')
// some processing here
index = # pointing to `NASDAQ` element here

how can I get the element full path as markets.us.summary.index?

amrezzd
  • 1,787
  • 15
  • 38
  • 1
    If you want to do it yourself, there are [some ideas here](https://stackoverflow.com/questions/191536/converting-xml-to-json-using-python). If you don't mind using lxml, [objectify does this](https://lxml.de/3.1/objectify.html). – fzzylogic May 21 '21 at 13:20
  • "full path as `markets.us.summary.index`" - you can get the full XPATH of the `` node (which will be something like `/markets/us/summary/index `) using lxml, if that's what your are really looking for. – Jack Fleeting May 21 '21 at 14:27

0 Answers0