[xml] Question about parent/child (python-libxml2)
- From: "W. Borgert" <debacle debian org>
- To: xml gnome org
- Subject: [xml] Question about parent/child (python-libxml2)
- Date: Sun, 9 May 2004 17:20:04 +0000
Hi,
how can I get the direct children of a node? The following
code:
#!/usr/bin/env python
import libxml2
dom = libxml2.parseDoc('''<?xml version="1.0"?>
<para role="x">Then, shalt thou count to
<emphasis>three</emphasis>, no more, no less.</para>''')
nodes = dom.xpathEval("//*[ role='x']")
for n in nodes:
if n.children:
for c in n.children:
if c.name == "comment":
continue
print c.serialize()
prints out:
Then, shalt thou count to
<emphasis>three</emphasis>
three
, no more, no less.
I like to print only the direct children, i.e. the second
last line with content 'three' should not be printed. How
can I achieve that? Thanks in advance!
Cheers,
--
W. Borgert <debacle debian org>, http://people.debian.org/~debacle/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]