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
 General SQL Server Forums
 New to SQL Server Programming
 Diff betn Element & Attribute centric

Author  Topic 

sqlpgmr
Starting Member

4 Posts

Posted - 2006-01-23 : 08:40:38
Friends,

In OPEN XML statements . i'm not able to distinguish the diff betn Element centric and attribute centric clearly??

Can any one throw some light on this ??

mwjdavidson
Aged Yak Warrior

735 Posts

Posted - 2006-01-25 : 07:03:00
Have a look at the entry for OPENXML in BOL, sqlpgmr. It's pretty thorough.
Basically, the flag controls what is mapped to the columns in your resultset. Take the following examples:
DECLARE @DocHandle int
DECLARE @XmlDocument nvarchar(1000)
SET @XmlDocument =
N'
<ROOT>
<Customer
CustomerID="1"
LastName="Davidson"
FirstName="Mark">
</Customer>
<Customer
CustomerID="2"
LastName="Smith"
FirstName="Bob">
</Customer>
</ROOT>'
-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @DocHandle OUTPUT, @XmlDocument
-- Execute a SELECT statement using OPENXML rowset provider.
SELECT *
FROM OPENXML (@DocHandle, '/ROOT/Customer',1)
WITH (CustomerID int,
LastName varchar(20),
FirstName varchar(20))
EXEC sp_xml_removedocument @DocHandle

SET @XmlDocument = N'
<ROOT>
<Customer>
<CustomerID>1</CustomerID>
<LastName>Davidson</LastName>
<FirstName>Mark</FirstName>
</Customer>
<Customer>
<CustomerID>2</CustomerID>
<LastName>Smith</LastName>
<FirstName>Bob</FirstName>
</Customer>
</ROOT>'
-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @DocHandle OUTPUT, @XmlDocument
-- Execute a SELECT statement using OPENXML rowset provider.
SELECT *
FROM OPENXML (@DocHandle, '/ROOT/Customer',2)
WITH (CustomerID int,
LastName varchar(20),
FirstName varchar(20))
EXEC sp_xml_removedocument @DocHandle

As you can see, you get the same result from two different XML documents by specifying attribute-centric or element-centric mapping.

Mark
Go to Top of Page
   

- Advertisement -