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

Discussion in 'Python' started by bijeshn@gmail.com, Mar 13, 2008.

  1. Guest

    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, 2008
    #1
    1. Advertising

  2. Chris Guest

    On Mar 13, 8:21 am, 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.
    Chris, Mar 13, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Nicholson
    Replies:
    3
    Views:
    722
    Rob Nicholson
    May 28, 2005
  2. Luis Esteban Valencia
    Replies:
    0
    Views:
    373
    Luis Esteban Valencia
    Jun 20, 2005
  3. shruds
    Replies:
    1
    Views:
    785
    John C. Bollinger
    Jan 27, 2006
  4. zheetee
    Replies:
    0
    Views:
    349
    zheetee
    Aug 5, 2004
  5. johkar
    Replies:
    4
    Views:
    493
    johkar
    Mar 13, 2007
Loading...

Share This Page