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

SQL 2005, is there a way to determine whether a specific n..

 
   Database Help (Home) -> XML RSS
Next:  select multiple items combo box  
Author Message
Dixie Normous

External


Since: Dec 31, 2008
Posts: 3



(Msg. 1) Posted: Wed Dec 31, 2008 9:04 am
Post subject: SQL 2005, is there a way to determine whether a specific node exists
Archived from groups: microsoft>public>sqlserver>xml (more info?)

For example, say I have the following XML:

..... [parentNode]

......... [test1][/test1]
......... [test2][/test2]

......... [subNode]
............. [subTest1]123[/subTest1]
............. [subTest2]234[/subTest2]
......... [/subNode]

..... [/parentNode]

Once I load the XML into a variable, there will be instances when
[subNode] may or may not exist. What's a straightforward method to
detect whether [subNode] is present?

Thanks in advance!!

 >> Stay informed about: SQL 2005, is there a way to determine whether a specific n.. 
Back to top
Login to vote
Martin Honnen

External


Since: Apr 20, 2007
Posts: 48



(Msg. 2) Posted: Wed Dec 31, 2008 1:25 pm
Post subject: Re: SQL 2005, is there a way to determine whether a specific node [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Dixie Normous wrote:
> For example, say I have the following XML:
>
> .... [parentNode]
>
> ........ [test1][/test1]
> ........ [test2][/test2]
>
> ........ [subNode]
> ............ [subTest1]123[/subTest1]
> ............ [subTest2]234[/subTest2]
> ........ [/subNode]
>
> .... [/parentNode]
>
> Once I load the XML into a variable, there will be instances when
> [subNode] may or may not exist. What's a straightforward method to
> detect whether [subNode] is present?

There is a method named exist on the XML data type:

DECLARE @x XML;
SET @x = N'<parentNode>
<test1></test1>
<test2></test2>

<subNode>
<subTest1>123</subTest1>
<subTest2>234</subTest2>
</subNode>

</parentNode>';

SELECT @x.exist('/parentNode/subNode');

You can pass in any XPath so for instance if you wanted to check there
is a 'subNode' element at any level you would use

SELECT @x.exist('//subNode');


--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/

 >> Stay informed about: SQL 2005, is there a way to determine whether a specific n.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
how to export view to display - xml with specific xsd? - I am converting an old access system to SQL Server 2005. In the previous system the users could click 'Export to xml' and the system prompted them for where to save the file. Then the developer wrote too much code to write the data out to an xml..

import xml to sql 2005 - Is there a tool to import xml to sql? Is there something else that can be used beside the Bulk Load Component. I would think MS had something. xml file is from store front. Thank you Dee

how to insert xml into sql 2005 - Using the following code how do I actually insert the data from the xml file into the sql 2005 database: declare @xml varchar(max) declare @xmlHandle int -- Bulk load the xml from the file set @xml = ( select * from openrowset (..

Create 2005 local cubes - I need to create a windows application in which I can programmatically create local cubes from SQL Server 2005 databases using C#. I was able to do this in SQL Server 2000, but I cannot get the same results after upgrading to 2005 because the CREATE..

How do you read an XML schema in SQL 2005 - I have some data that came to me in XSD. How can this be read into an SQL 2005 database? I also have a few XML Schemas and need to know how this can be ready into an SQL 2005 database? Thanks for any help Dee
   Database Help (Home) -> XML All times are: Pacific Time (US & Canada)
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 ]