I have now read many (maybe all) posts on excluding elements in XPath and I just do not get this working. I have no clue why.
Let\'s say I have the following structu
XPath is for selection. What you want to select does not exist in your XML document.
You need another tool such as XSLT to generate an XML output document based on an input XML document. XSLT can generate your desired output trivially via the identity transformation supplemented with a simple template that suppresses the copying of the element that you do not want (elemC
):
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="elemC"/>
</xsl:stylesheet>
XPath alone cannot help you.