xml filtering with python

Posted by saminny on Stack Overflow See other posts from Stack Overflow or by saminny
Published on 2010-05-19T21:30:11Z Indexed on 2010/05/19 22:30 UTC
Read the original article Hit count: 140

Filed under:

Hi,

I have a following xml document:

<node1>
  <node2 a1="x1"> ... </node2>
  <node2 a1="x2"> ... </node2>
  <node2 a1="x1"> ... </node2>
</node1>

I want to filter out node2 when a1 = x2. The user provides the xpath and attribute values that need to tested and filtered out. I looked at some solutions in python like BeautifulSoup but they are too complicated and dont preserve the case of text. I want to keep the document same as before with some stuff filtered out.

Can you recommend a simple and succinct solution? This should not be too complicated from the looks of it. The actual xml document is not as simple as above but idea is the same.

© Stack Overflow or respective owner

Related posts about python