Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
xml parsing with xquery returning null records
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Dan  
View profile  
 More options Apr 4 2011, 6:08 pm
Newsgroups: microsoft.public.sqlserver.xml
From: Dan <dqui...@gmail.com>
Date: Mon, 4 Apr 2011 15:08:13 -0700 (PDT)
Local: Mon, Apr 4 2011 6:08 pm
Subject: xml parsing with xquery returning null records
I've recently begun receiving xml files and ran into a small problem
that seems syntax related, but I simply can't find where it is.  Below
is the xml file and sample code of what I'm doing. I cut up the xml
data, it's far more complex then what I'm presenting below.  I think
it has something to do what how I'm address eventId but am struggling
with figuring it out.  My preference is to stay out of SSIS if at all
possible on this project.

I'm getting rows to return, but they are all null when there is data
in the file.

If you see something with what I'm doing (and replied), I'd be greatly
thankful.

<?xml version="1.0" encoding="UTF-8"?>
<pitchMediaList>
  <pitchMedia eventId="243">
    <media type="FLASH" url="xx.html"/>
  </pitchMedia>
</pitchMediaList>

select x.value('eventId[1]/eventId[1]','int') as url
FROM (
SELECT CAST(x AS XML)
FROM OPENROWSET(
     BULK 'c:\videofile.xml',
     SINGLE_BLOB) AS T(x)
     ) AS T(x)
CROSS APPLY x.nodes('pitchMediaList/pitchMedia') AS X(pitchMedia);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erland Sommarskog  
View profile  
 More options Apr 5 2011, 3:20 am
Newsgroups: microsoft.public.sqlserver.xml
From: Erland Sommarskog <esq...@sommarskog.se>
Date: Tue, 5 Apr 2011 07:20:11 +0000 (UTC)
Local: Tues, Apr 5 2011 3:20 am
Subject: Re: xml parsing with xquery returning null records

When you retrieve attribute, you need to put an @ in front:

DECLARE @x xml
SELECT @x = '<?xml version="1.0" encoding="UTF-8"?>
<pitchMediaList>
  <pitchMedia eventId="243">
    <media type="FLASH" url="xx.html"/>
  </pitchMedia>
</pitchMediaList>'

select X.c.value('@eventId[1]','int') as url
FROM @x.nodes('pitchMediaList/pitchMedia') AS X(c);

--
Erland Sommarskog, SQL Server MVP, esq...@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »