Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > copying all data(tags and values) after a particular XML tag

Reply
Thread Tools

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

 
 
bijeshn@gmail.com
Guest
Posts: n/a
 
      03-13-2008
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.
 
Reply With Quote
 
 
 
 
Chris
Guest
Posts: n/a
 
      03-13-2008
On Mar 13, 8:21*am, (E-Mail Removed) 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing an XML file and adding another tag, if the tag is not available / the value is null P Perl Misc 7 01-12-2007 03:28 AM
only a simple xml reader <tag:id>value</tag:id> martijn@gamecreators.nl Python 4 02-11-2006 06:44 PM
how do u invoke Tag b's Tag Handler from within Tag a's tag Handler? shruds Java 1 01-27-2006 03:00 AM
Parsing an XML file for a particular element, reading the children, and getting database values Luis Esteban Valencia ASP .Net 0 06-20-2005 12:54 PM
How to search a particular word in xml and display all the result in webpage by using asp or... zheetee XML 0 08-05-2004 07:25 AM



Advertisments