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

B

bijeshn

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.
 
C

Chris

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top