Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #48845 > unrolled thread
| Started by | dieter <dieter@handshake.de> |
|---|---|
| First post | 2013-06-21 08:17 +0200 |
| Last post | 2013-06-21 08:17 +0200 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Finding all instances of a string in an XML file dieter <dieter@handshake.de> - 2013-06-21 08:17 +0200
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2013-06-21 08:17 +0200 |
| Subject | Re: Finding all instances of a string in an XML file |
| Message-ID | <mailman.3653.1371795459.3114.python-list@python.org> |
Jason Friedman <jsf80238@gmail.com> writes: > I have XML which looks like: > > <?xml version="1.0" encoding="UTF-8"?> > <!DOCTYPE KMART SYSTEM "my.dtd"> > <LEVEL_1> > <LEVEL_2 ATTR="hello"> > <ATTRIBUTE NAME="Property X" VALUE ="2"/> > </LEVEL_2> > <LEVEL_2 ATTR="goodbye"> > <ATTRIBUTE NAME="Property Y" VALUE ="NULL"/> > <LEVEL_3 ATTR="aloha"> > <ATTRIBUTE NAME="Property X" VALUE ="3"/> > </LEVEL_3> > <ATTRIBUTE NAME="Property Z" VALUE ="welcome"/> > </LEVEL_2> > </LEVEL_1> > > 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. This is a high end approach: you would use a powerful (and big) infrastructure (but one which could also be of use for other XML applications). There are more elementary approaches as well (e.g. parse the XML into a DOM and provide your own visitor to find the elements you are interested in).
Back to top | Article view | comp.lang.python
csiph-web