Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Return all Elements from XML Segment (SQL 2005)

 
   Database Help (Home) -> XML RSS
Next:  Response time  
Author Message
kkam99504

External


Since: Aug 29, 2008
Posts: 1



(Msg. 1) Posted: Fri Aug 29, 2008 12:41 pm
Post subject: Return all Elements from XML Segment (SQL 2005)
Archived from groups: microsoft>public>sqlserver>xml (more info?)

Hi,
I need to be able to return all Elements from an XML segment that is
stored in a SQL 2005 XML column. The column does not have an associated
schema as the XML segment has multiple formats. All that is consistent is
that there will be a common root element. After that any number of Elements
may exist within it.

For example:
<objdata>
<ProjectName>My Project Name Here</ProjectName>
<Project_Number>1150700</Project_Number>
<Latitude_Decimal>61.17</Latitude_Decimal>
<Longitude_Decimal>150.02</Longitude_Decimal>
</objdata>

would need to return:

ProjectName
Project_Number
Latitude_Decimal
Longitude_Decimal

Any suggestions will be considered. I'd prefer to refrain from using
Cursors or CLR.

Thanks,
- Kurt

 >> Stay informed about: Return all Elements from XML Segment (SQL 2005) 
Back to top
Login to vote
Bob

External


Since: Feb 08, 2005
Posts: 166



(Msg. 2) Posted: Sat Aug 30, 2008 4:29 am
Post subject: RE: Return all Elements from XML Segment (SQL 2005) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Try:

DECLARE @xml XML

SET @xml = '
<objdata>
<ProjectName>My Project Name Here</ProjectName>
<Project_Number>1150700</Project_Number>
<Latitude_Decimal>61.17</Latitude_Decimal>
<Longitude_Decimal>150.02</Longitude_Decimal>
</objdata>
'

SELECT x.y.value( 'local-name(.)', 'varchar(100)' )
FROM @xml.nodes( 'objdata/*' ) x(y)

HTH
wBob


"kkam99504" wrote:

> Hi,
> I need to be able to return all Elements from an XML segment that is
> stored in a SQL 2005 XML column. The column does not have an associated
> schema as the XML segment has multiple formats. All that is consistent is
> that there will be a common root element. After that any number of Elements
> may exist within it.
>
> For example:
> <objdata>
> <ProjectName>My Project Name Here</ProjectName>
> <Project_Number>1150700</Project_Number>
> <Latitude_Decimal>61.17</Latitude_Decimal>
> <Longitude_Decimal>150.02</Longitude_Decimal>
> </objdata>
>
> would need to return:
>
> ProjectName
> Project_Number
> Latitude_Decimal
> Longitude_Decimal
>
> Any suggestions will be considered. I'd prefer to refrain from using
> Cursors or CLR.
>
> Thanks,
> - Kurt

 >> Stay informed about: Return all Elements from XML Segment (SQL 2005) 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> XML All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]