Return the path of an XML Node

  • I need to be able to return the path of a specific node in an XML File.

    Here is an example:

    declare @xml xml

    select @xml =

    '[Script isChecksum="1" checksum="1819591268" studioBuild="3300" studioVersion="6.3.11.4732"]

    [Subroutine name="Main" description="" export="0"]

    [ScriptGraph name="Script" _id="423"]

    [Nodes]

    [BlockNode name="GetServerTime"]

    [Inputs]

    [Input _id="7" name="Input" breakpoint="0" id="0" /]

    [/Inputs]

    [Outputs]

    [UserOutput input="8" name="Output" /]

    [/Outputs]

    [BlockGraph]

    [Nodes]

    [DbSelect name="DBSelectValidateDOCID"]

    [Inputs]

    [Input _id="10" name="" breakpoint="0" id="0" /]

    [/Inputs]

    [/DbSelect]

    [/Nodes]

    [/BlockGraph]

    [/BlockNode]

    [/Nodes]

    [/ScriptGraph]

    [/Subroutine]

    [/Script]'

    I can do select @xml.query('//DbSelect') to get the DbSelect nodes but how do I return the entire path as a string i.e. [Script/Subroutine/ScriptGraph/Nodes/BlockNodes/BlockGraph/Nodes/DbSelect]

    The parent node would also be fine in I could some how return that.

    Thanks for you help

  • Hi,

    it looks like the thread just ignored your xml sample data.

    Please use [ code="xml" ] tags without spaces.



    Lutz
    A pessimist is an optimist with experience.

    How to get fast answers to your question[/url]
    How to post performance related questions[/url]
    Links for Tally Table [/url] , Cross Tabs [/url] and Dynamic Cross Tabs [/url], Delimited Split Function[/url]

  • You can see the code now. Any help would really be appreciated.

    Thanks,

    Wyeth

  • Seems to be problematic. You would the XPath function "base-uri()" which is currently (until SQL Server 2008) not supported for T-SQL XQuery.

    Here is a Microsoft link which confirms this:

    http://msdn.microsoft.com/en-us/library/ms345122(SQL.90).aspx

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply