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 2008 Forums
 Transact-SQL (2008)
 Convert nVarchar and insert into XML column

Author  Topic 

pagan1234
Starting Member

7 Posts

Posted - 2010-02-21 : 10:47:58
Hi All,
I have checked online about this issue but with no luck.
I'm trying to do Insert into from xml data (nVarchar(max)) to an xml datatype column but this always gives me Illegal xml character error. Here is the sample code..

create table #temp(XMLCol xml)
Insert into #temp select convert(xml,messagebody) as MessageBody from dbo.StrTable


How ever, if i can insert into this table as follows

Insert into #temp (XmlCol) values ('<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer''s Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.</description>
</book>
</catalog>')

select * from #temp

Can some one please help me.

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-21 : 10:58:20
that may be because xml value contained in nvarchar(max) field is not well formed.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

pagan1234
Starting Member

7 Posts

Posted - 2010-02-21 : 11:36:58
Visakh, I actually was able to insert into table by copying the xml like i stated above.
Go to Top of Page
   

- Advertisement -