Re: Finding all instances of a string in an XML file

2013-06-23 Thread Jason Friedman
> xml = """ > > > > > > > > > > > > > > """ > > import xml.etree.ElementTree as etree > > tree = etree.fromstring(xml) > > def walk(elem, path, token): > path += (elem,) > if token in elem.attrib.values(): > yield path > for child i

Re: Finding all instances of a string in an XML file

2013-06-21 Thread Jason Friedman
Thank you Peter and Dieter, will give those thoughts a try and report back. -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding all instances of a string in an XML file

2013-06-20 Thread dieter
Jason Friedman writes: > I have XML which looks like: > > > > > > > > > > > > > > > > > The "Property X" string appears twice times and I want to output the "path" > that leads to all such appearances. You could use "lxml" and its "xpath" support.

Re: Finding all instances of a string in an XML file

2013-06-20 Thread Peter Otten
Jason Friedman wrote: > I have XML which looks like: > > > > > > > > > > > > > > > > > The "Property X" string appears twice times and I want to output the > "path" > that leads to all such appearances. In this case the output would be: > > LEVE

Finding all instances of a string in an XML file

2013-06-20 Thread Jason Friedman
I have XML which looks like: The "Property X" string appears twice times and I want to output the "path" that leads to all such appearances. In this case the output would be: LEVEL_1 {}, LEVEL_2 {"ATTR": "hello"}, ATTRIBUTE {"NAME": "Property X",