How To Copy All Nodes Of An XML Document And Add An Atrribute To Each Node


Have you ever wanted to copy all nodes of an xml document, and add an attribute to each node?




<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="" exclude-result-prefixes="xsl">
  <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
  <xsl:template match="*">
      <xsl:copy-of select="@*"/>
      <xsl:attribute name="dirty">true</xsl:attribute>




I had a problem, in that I had an Object that had over 50+ properties.  When I took in XML and deserialized it, I did not know what nodes were supplied.  I wanted to allow folks to pass in just the parts of the document they wanted to update, but had no notion of "dirty".  This will add a "dirty" attribute to all nodes, which allows me to easily grab only the dirty ones, and update my database accordingly.

Comments (1) -

Archive Storage
Archive Storage
1/4/2012 7:37:18 AM #

Really i am impressed from this post....the person who created this post is a genious and knows how to keep the readers connected..thanks for sharing this with us.i found it informative and interesting. Looking forward for more updates..

Pingbacks and trackbacks (1)+

Add comment

  Country flag

  • Comment
  • Preview