Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two Xml in my output as xml editor
XML
<Contact>
  <PLate>
    <PlateId>60</PlateId>
    <ActionId>1</ActionId>
  </PLate>
</Contact>


and second one as
XML
<Contact>
  <PLate>
    <PlateId>59</PlateId>
    <ActionId>2</ActionId>
  </PLate>
</Contact>



How to Concatenate this two xml to get final result as
XML
<Contact>
  <PLate>
    <PlateId>60</PlateId>
    <ActionId>1</ActionId>
  </PLate>
</Contact>
<Contact>
  <PLate>
    <PlateId>59</PlateId>
    <ActionId>2</ActionId>
  </PLate>
</Contact>
Posted
Updated 24-Oct-12 10:22am
v2
Comments
Sergey Alexandrovich Kryukov 22-Oct-12 15:09pm    
Is either of the XML string a complete XML starting from a document element? If this is so, the result of concatenation is not well-formed XML. For example, your resulting XML code is not well-formed XML. It could be valid only as inner XML of some other document. Do you take it into account? If not, the whole thing makes no sense.
--SA

1 solution

You can simply cast it to varchar(max)/nvarchar(max), concatenate and then
cast it back.
SQL
declare @x xml, @y xml
select @x = '<contact>
  <plate>
    <plateid>60</plateid>
    <actionid>1</actionid>
  </plate>
</contact>'

select @y = '<contact>
  <plate>
    <plateid>59</plateid>
    <actionid>2</actionid>
  </plate>
</contact>'

select cast(cast(@x as nvarchar(max)) + cast(@y as nvarchar(max)) as xml)
 
Share this answer
 
Comments
damodara naidu betha 25-Oct-12 1:23am    
5+
Aadhar Joshi 25-Oct-12 3:24am    
thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900