﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / SQL Server 2005 / SQL Server Newbies  / Problem with openxml / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Tue, 21 May 2013 15:09:15 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Problem with openxml</title><link>http://www.sqlservercentral.com/Forums/Topic1424872-1291-1.aspx</link><description>The immediate problem is having PKID set as an IDENTITY. Ditch that and it will run as is.[code="sql"]PKID INT [strike]IDENTITY(1,1)[/strike] NOT NULL[/code]Another thing that can cause a problem is the mapping flag for the OPENXML command. You don't specify a value so it defaults to zero and attribute-centric mapping. Fortunately, that is what you are trying to do. But it's better if you specify a value of 1 (a value of 2 is for element-centric mapping...enter a 2 and see what happens):[code="sql"]...FROM OPENXML(@hdoc,'//row',1) WITH PrintRequestRows[/code]Final suggestion is to use a TRY/CATCH block for sp_xml_prepare&amp;#100;ocument. I always declare and build my XML as a string first so I can use various functions for removing excess spaces, invalid characters, etc.[code="sql"]    BEGIN TRY        EXEC sp_xml_preparedocument @idoc OUTPUT, @strXML    END TRY    BEGIN CATCH        BEGIN                        IF @debug = 1                BEGIN                    SELECT @strXML AS ModifiedXML                    SELECT CONVERT(XML,@strXML) AS FormattedXML                        END                        SELECT               'Invalid XML' AS XMLStatus                RETURN                            END    END CATCH[/code] </description><pubDate>Wed, 27 Feb 2013 23:19:09 GMT</pubDate><dc:creator>Steven Willis</dc:creator></item><item><title>Problem with openxml</title><link>http://www.sqlservercentral.com/Forums/Topic1424872-1291-1.aspx</link><description>Hi,I'm trying to read a column from the xml using openxml. Things are fine except while trying to read one column both by select statement and while using a CTE, i get column not found error.Can anyone advise why i'm getting this error even though the column is present both in xml data and table definition.I've attached the script for having an idea of the problem i'm facing.thanks :)</description><pubDate>Wed, 27 Feb 2013 20:59:53 GMT</pubDate><dc:creator>S-322532</dc:creator></item></channel></rss>