Page 1 of 1

Parsing XML like txt

Posted: Thu Apr 30, 2015 1:44 pm
by TomT
Hi,

I like to parse an xml file to delete a node without deleting the child nodes by using a script. So I have the following XML structure:

node a
--- node b
------node c

Now I like to delete node a by parsing the xml file for the "<node a>" tag. The difficulty for me is to

- find a variable which could pickup the xml file and
- to find a variable to store the xml file content as a string

so that I can parse the xml content.

Kind regards

TomT

Re: Parsing XML like txt

Posted: Thu Apr 30, 2015 5:02 pm
by dkelly
Use this style sheet

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>
<xsl:template match="/*">
  <xsl:apply-templates select="node()" />
</xsl:template>

</xsl:stylesheet>
to convert from

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<a>
  <b>
    <c/>
  </b>
</a>
to

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<b>
  <c/>
</b>