Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 modify xml node name

Author  Topic 

Jason100
Starting Member

34 Posts

Posted - 2010-01-14 : 21:09:55
DECLARE @xml XML
SET @xml ='
<ItemsList>
<A>123 </A>
<B>123 </B>
<IdMapping>
<Inv>
<Id>001 </Id>
<Type>A01 </Type>
<Part>01 </Part>
</Inv>
<Inv>
<Id>002 </Id>
<Type>A02 </Type>
<Part>02 </Part>
</Inv>
<Inv>
<Part>03 </Part>
</Inv>
<Inv>
<Part>05 </Part>
</Inv>
<Inv>
<Part>09 </Part>
</Inv>
</IdMapping>
</ItemsList>'
SELECT @xml

result1:
If this is value on the node <Id> </Id>, I want to drop all the node <Part> </Part>

SET @xml ='
<ItemsList>
<A>123 </A>
<B>123 </B>
<IdMapping>
<Inv>
<Id>001 </Id>
<Type>A01 </Type>
</Inv>
<Inv>
<Id>002 </Id>
<Type>A02 </Type>
</Inv>
</IdMapping>
</ItemsList>'

result2:
If this is not any value on node <Id> </Id>, I want to re-name the node <Inv> </Inv> to <NewInv> </NewInv>
SET @xml ='
<ItemsList>
<A>123 </A>
<B>123 </B>
<IdMapping>
<NewInv>
<Part>03 </Part>
</NewInv>
<NewInv>
<Part>05 </Part>
</NewInv>
<NewInv>
<Part>09 </Part>
</NewInv>
</IdMapping>
</ItemsList>'

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-14 : 23:59:20
have a look at delete() and replace in

http://msdn.microsoft.com/en-us/library/ms177454.aspx

this would give you a start
Go to Top of Page
   

- Advertisement -