remove extraenious information between XML tags

J

Jarry

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
 
J

Johannes Koch

Jarry said:
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').
 
A

Andy Dingley

Jarry said:
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>
 

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
474,005
Messages
2,570,264
Members
46,859
Latest member
HeidiAtkin

Latest Threads

Top