Shredding XML that contains a namespace

  • I am having a problem shredding XML parameters, where the XML contains a namespace.

    Has anyone else experienced this issue? I realise I can get the developers to strip this from the XML before passing it, or remove it myself prior to shredding it but was hoping for an alternative cleaner solution.

    Example code used within a SP - Please replace {} with <>, as I couldn't post with angle brackets <>.

    DECLARE @xml XML

    SET @xml = '

    {OrderDTO xmlns="http://tempuri.org/"}

    {Product}

    {Item}Juice{/Item}

    {Price}19.99{/Price}

    {/Product}

    {/OrderDTO}'

    SELECT

    Table1.Column1.value('Item[1]', 'VARCHAR(100)'),

    Table1.Column1.value('Price[1]', 'MONEY')

    FROM

    @xml.nodes('/OrderDTO/Product') AS Table1(Column1)

    If the xmlns is removed, or set to "" it works.

    Thanks in advance,

    Mark

  • Mark -

    Barry and I kind of stumbled on that the other day. Take a look over here...

    http://www.sqlservercentral.com/Forums/FindPost483865.aspx

    You essentially have to "take the namespace on head-on", meaning declare it and work around it...

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

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

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