XML Nodes - Copying

  • Thread starter Thread starter JJ
  • Start date Start date
J

JJ

I need to basically copy an entire XML document to another XML document.

The first needs to be an exact copy of the second, and I need to do it a
node at a time as I am omitting certain nodes that have certain attributes.

Whats the best way of doing this?

JJ
 
JJ said:
I need to basically copy an entire XML document to another XML document.

The first needs to be an exact copy of the second, and I need to do it a
node at a time as I am omitting certain nodes that have certain attributes.

An exact copy omits certain nodes?
Whats the best way of doing this?

Sounds like an easy job for an XSLT stylesheet with two templates, one
the identity transformation, the second for those elements to be omitted
e.g.

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="element-name[@attribute-name]" />

You can run XSLT transformations in .NET 1.x with XslTransform, in .NET
2.x with XslCompiledTransform.
 
Back
Top