By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,908 Members | 1,860 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,908 IT Pros & Developers. It's quick & easy.

copying all data(tags and values) after a particular XML tag

P: n/a
i've an XML file with the following structure....

<a>
<b>
<c>
..
..
..
..
..</c>
</b>
</a>

what i want to do is copy all data(tags and all) between N and N+k
appearances of <c>. I am a python newbie. How do I do it?

Thanks.
Mar 13 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mar 13, 8:21*am, bije...@gmail.com wrote:
i've an XML file with the following structure....

<a>
<b>
<c>
.
.
.
.
.</c>
</b>
</a>

what i want to do is copy all data(tags and all) between N and N+k
appearances of <c>. I am a python newbie. How do I do it?

Thanks.
You can take a look at the docs for Beautiful Soup, they might help
you. If it's just as simple as you're describing and you could always
do something like...

test = """<a>
<b>
<c>
1
</c>
</b>
<b>
<c>
2
</c>
</b>
</a>"""

test = test.replace('<c>','|||').replace('</c>','|||')
[i for (j,i) in enumerate(tmp2.split('|')) if j%2]

which would yield
['\n 1\n ', '\n 2\n ']

which you could then parse as required.
Mar 13 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.