1

I want to insert this XML data into SQL Server 2008

<rewriteMap name="OldStaticUrl">
   <add key="/about/" value="/about" />
   <add key="/2march2012" value="/community/0770/welcome-to-electronic-musicians-march-2012-links-page/147452" />
</rewriteMap>

I am using this SQL query

DECLARE @hdoc INT
DECLARE @doc varchar(1000)

SET @doc = '<rewriteMap name="OldStaticUrl">
               <add key="/about/" value="/about" />
               <add key="/2march2012" value="/community/0770/welcome-to-electronic-musicians-march-2012-links-page/147452" />
            </rewriteMap>'

 EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc

 SELECT vanity, originalurl
  FROM Openxml(@hdoc, '/rewriteMap/add',1) 
  WITH (vanity varchar(1000), originalurl varchar(1000))

But I am getting null in the result set, in fact if I use select * from openxml, I get multiple rows, some of which contains proper data.

1 Answer 1

3

Instead of vanity and originalurl literals you should use key and value respectively.
Try this query:

DECLARE @hdoc INT
DECLARE @doc varchar(1000)
SET @doc = '<rewriteMap name="OldStaticUrl">
                <add key="/about/" value="/about" />
                <add key="/2march2012" value="/community/0770/welcome-to-electronic-musicians-march-2012-links-page/147452" />
            </rewriteMap>'
EXEC sp_xml_preparedocument @hdoc OUTPUT, @doc
SELECT [key], value
FROM Openxml( @hdoc, '/rewriteMap/add', 1) WITH ( [key] varchar(1000), value varchar(1000) )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.