Source:
<row>
<col_a>5</col_a>
<col_b>7</col_b>
<col_c>9</col_c>
</row>
Target:
<row>
<col_a>5</col_a>
<col_b Changed="Y">10</col_b>
<col_c Changed="Y">11</col_c>
</row>
Is there any method(s) to add attribute(s) into xml tags as above example?
ABC wrote:
> <row>
> <col_a>5</col_a>
> <col_b Changed="Y">10</col_b>
> <col_c Changed="Y">11</col_c>
> </row>
>
> Is there any method(s) to add attribute(s) into xml tags as above example?
Yes, use the XML method modify and the insert statement:
DECLARE @.x xml;
SET @.x = '<row>
<col_a>5</col_a>
<col_b>7</col_b>
<col_c>9</col_c>
</row>';
SET @.x.modify('
replace value of (row/col_b/text())[1]
with 10
');
SET @.x.modify('
insert attribute Changed {"Y"}
into (row/col_b)[1]
');
SELECT @.x;
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/
Wednesday, March 7, 2012
How to add an attribute to xml tags?
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment