XPath does not modify any source XML document, and this is by design .
To create a new XML document from an existing one, a conversion is required.
XSLT was specifically designed to convert a set of trees (including XML documents) into result trees.
This conversion is :
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="/*"> <xsl:copy> <xsl:copy-of select="@*"/> </xsl:copy> </xsl:template> </xsl:stylesheet>
when applied to the provided XML document :
<Customer id=""> <Name /> <Address /> </Customer>
creates the desired, correct result :
<Customer id=""/>
source share