Home Forums Programming XML How to filter the namespace from the xml in SQLServer..plz help RE: How to filter the namespace from the xml in SQLServer..plz help

  • Here you go, here are two example queries querying an xml structure that has a namespace. The first query will actually include some auto generated prefixes by SQL, but the second query doesn't:

    DECLARE @xml XML

    SET @xml = '

    <XML xmlns="https://temp.../test.xsd">

    <Content>

    <Data>

    <Node1>1</Node1>

    <Node2>2</Node2>

    </Data>

    <Data>

    <Node1>1</Node1>

    <Node2>2</Node2>

    </Data>

    </Content>

    </XML>'

    --using WITH XMLNAMESPACES

    ;WITH XMLNAMESPACES(DEFAULT 'https://temp.../test.xsd')

    SELECT @xml.query('//Content')

    --OR to return xml without the p1 prefixes:

    SELECT @xml.query(

    'declare default element namespace "https://temp.../test.xsd";

    //Content')