﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Programming / XML  / capturing multiple attributes from node / 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>Sat, 25 May 2013 06:36:08 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: capturing multiple attributes from node</title><link>http://www.sqlservercentral.com/Forums/Topic1390918-21-1.aspx</link><description>The new xml functions runs more effeciently than the old OPENXML, that is why you suggest this?  If I have a file I need to load, I was use[code="sql"]SET @xml = 'location of xml'[/code]In your example does the brackets [1] specify that there are more than one value or is it the cross apply? This would work whether there would be 1,2 and 3 or more authors, correct? So in your example I would do this:[code="sql"]Insert into tblBook SELECT a.c.value('(BookNumber/text())[1]', 'int')	, b.c.value('(@name)[1]', 'varchar(30)')FROM @xml.nodes('/xml/Document/FileDetail') AS a(c)CROSS APPLY a.c.nodes('BookAuthorLoop/Author') AS b(c)[/code]I would then I have one row of record containing[code="other"]BookNumber             Book Author1234                       John Doe, Jane Doe[/code]When I query for the book number in the table?Thanks for taking the time to help.</description><pubDate>Fri, 30 Nov 2012 10:00:08 GMT</pubDate><dc:creator>eripey</dc:creator></item><item><title>RE: capturing multiple attributes from node</title><link>http://www.sqlservercentral.com/Forums/Topic1390918-21-1.aspx</link><description>Hi,I would use the newer XML functions rather then the old OPENXML. Syntax wise you could probably do this in a couple of ways, but here is one that I have come up with (i've tweaked your example xml to make it valid)[code="sql"]DECLARE @xml XMLSET @xml = '&amp;lt;xml&amp;gt;&amp;lt;Document&amp;gt;&amp;lt;FileDetail&amp;gt;&amp;lt;BookNumber&amp;gt;12345&amp;lt;/BookNumber&amp;gt;&amp;lt;BookAuthorLoop&amp;gt;	&amp;lt;Author name="John Doe"/&amp;gt;	&amp;lt;Author name="Jane Doe"/&amp;gt;&amp;lt;/BookAuthorLoop&amp;gt;&amp;lt;/FileDetail&amp;gt;&amp;lt;/Document&amp;gt;&amp;lt;/xml&amp;gt;'SELECT a.c.value('(BookNumber/text())[1]', 'int')	, b.c.value('(@name)[1]', 'varchar(30)')FROM @xml.nodes('/xml/Document/FileDetail') AS a(c)CROSS APPLY a.c.nodes('BookAuthorLoop/Author') AS b(c)[/code]</description><pubDate>Fri, 30 Nov 2012 08:07:08 GMT</pubDate><dc:creator>arthurolcot</dc:creator></item><item><title>capturing multiple attributes from node</title><link>http://www.sqlservercentral.com/Forums/Topic1390918-21-1.aspx</link><description>If I have an xml file below[code="xml"]&amp;lt;xml&amp;gt;&amp;lt;Document&amp;gt;&amp;lt;FileDetail&amp;gt;&amp;lt;BookNumber&amp;gt;12345&amp;lt;/BookNumber&amp;gt;&amp;lt;BookAuthorLoop&amp;gt;&amp;lt;Author name="John Doe"&amp;gt;&amp;lt;Author name="Jane Doe"&amp;gt;&amp;lt;/DetailLoop&amp;gt;&amp;lt;/FileDetail&amp;gt;&amp;lt;/Document&amp;gt;[/code]Right now my sql code looks like this and only captures the first author, how do I get it to get both Authors name, do I need to loop it of some kind?[code="sql"]Insert into tblBookSelect *From OpenXMLWith (BookNumber varchar(50) '/Document/FileDetail/BookNumber',BookAuthor varchar(500) '/Document/FileDetail/BookAuthorLoop/Author/@name')[/code]The table looks like this[code="other"]BookNumber  BookAuthor1234            John Doe[/code]I would like it to capture all authors like this[code="other"]Book Number         Book Author1234                    John Doe, Jane Doe[/code]Any help/guidance will be greatly appreciated.  Thanks.</description><pubDate>Thu, 29 Nov 2012 17:17:41 GMT</pubDate><dc:creator>eripey</dc:creator></item></channel></rss>