Question

I'm working with TextWrangler's find and replace function. I have a folder of XML files that all include this tag:

<song xmlns="http://openlyrics.info/namespace/2009/song" version="0.8" createdIn="OpenLP 2.0.1" modifiedIn="OpenLP 2.0.1" modifiedDate="2013-06-23T21:33:21">

I would like to remove the namespaces and other info from the tag and get just this:

<song>

My issue is twofold:

  1. First, I can't get TextWrangler to find anything that includes angle brackets. I don't know how to search for a literal angle bracket.
  2. The modifiedDate= part of the tag is different for each file. Therefore, I need something that will find all text contained in the tag, no matter what it says.

Any suggestions?

Était-ce utile?

La solution

It's really worth acquiring sufficient familiarity with XSLT for this kind of task. Doing it in a text editor will always have limitations (for example your code is quite likely to depend on the attributes being in a particular order). It's probably as simple as this:

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates/>
  </xsl:element>
</xsl:template>

</xsl:transform>

This will in fact remove namespaces and attributes from all elements, not just the song element, but this can easily be changed by adding another template rule.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top