remove extraenious information between XML tags

Discussion in 'XML' started by Jarry, Aug 29, 2006.

  1. Jarry

    Jarry Guest

    I was editing a huge XML file that a friend of mine had made and I
    didn't need some of the tags. WHen I was finished editing it, I
    realised I had a lot of information between tags, in no man's land. eg:
    <team>
    <player>
    <name>David Beckham</name> REAL MADRID
    <position> Right Midfield </position>
    </player>
    </team>

    How would I remove the Real Madrid type text on thousand of entries?

    Thanks
    Jarry, Aug 29, 2006
    #1
    1. Advertising

  2. Jarry wrote:
    > I was editing a huge XML file that a friend of mine had made and I
    > didn't need some of the tags. WHen I was finished editing it, I
    > realised I had a lot of information between tags, in no man's land. eg:
    > <team>
    > <player>
    > <name>David Beckham</name> REAL MADRID
    > <position> Right Midfield </position>
    > </player>
    > </team>
    >
    > How would I remove the Real Madrid type text on thousand of entries?


    Select the player element, then remove all non-whitespace text child
    nodes (or text child nodes containing 'REAL MADRID').
    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)
    Johannes Koch, Aug 29, 2006
    #2
    1. Advertising

  3. Jarry

    Andy Dingley Guest

    Jarry wrote:

    > I was editing a huge XML file that a friend of mine had made and I
    > didn't need some of the tags. WHen I was finished editing it, I
    > realised I had a lot of information between tags, in no man's land. eg:


    They're not in "no man's land", they're text children of the <player>
    element that aren't children of another element.

    You've already had one good answer to this, but my personal choice
    would be to use XSLT.

    First of all, find the XSLT "identity" stylesheet (web search, I'm too
    lazy). This copies input documents exactly, without changing them. Then
    (a very useful general XSLT technique) add particular template rules to
    this to cope with the situations where you don't want a simple identity
    copy. In your case this would be something like this

    <xsl:template match="player" >
    <player>
    <xsl:apply-templates select="*" />
    </player>
    </xsl:template>
    Andy Dingley, Aug 29, 2006
    #3
    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. theintrepidfox
    Replies:
    0
    Views:
    278
    theintrepidfox
    Nov 26, 2007
  2. mcnewsxp
    Replies:
    6
    Views:
    1,336
    dorayme
    Nov 25, 2010
  3. theintrepidfox
    Replies:
    0
    Views:
    113
    theintrepidfox
    Nov 26, 2007
  4. Aaron  Fleming

    Remove content between tags

    Aaron Fleming, Mar 15, 2005, in forum: ASP General
    Replies:
    1
    Views:
    115
    McKirahan
    Mar 15, 2005
  5. replacing tags between tags

    , Sep 18, 2005, in forum: Perl Misc
    Replies:
    9
    Views:
    117
    J├╝rgen Exner
    Sep 19, 2005
Loading...

Share This Page