I am trying to accomplish with lxml library something like this: http://www.xml.com/pub/a/2005/01/19/amara.html
from amara import binderytools
container = binderytools.bind_file('labels.xml')
for l in container.labels.label:
print l.name, 'of', l.address.city
but I have had the hardest time to get my feel wet! What I want to do is: descend to the root node named 'X', then descend to its second child named 'Y', then grab all of its children 'named Z', then of those keep only the children than have an attribute 'name' set to 'bacon', then for each remaining node look at all of its children named 'W', and keep only a subset based on some filter, which looks at W's only children named A, B, and C. Then I need to process them with the following (non-optimized) pseudo-code:
result = []
X = root(doc(parse(xml_file_name)))
Y = X[1] # Second child
Zs = Y.children()
for Z in Zs:
if Z.name != 'bacon': continue # skip
Ws = Z.children()
record = []
assert(len(Ws) == 9)
W0 = Ws[0]
assert(W0.A == '42')
record.append(str(W0.A) + " " + W0.B + " " + W0.C))
...
W1 = Ws[1]
assert(W1.A == '256')
...
result.append(record)
This is sort of what I am trying to accomplish. Before I try to make this code cleaner, I would like to make it work.
Please help, as I am lost in this API. Let me know if you have questions.