sql server - MS SQL iterate through XML with default namespaces -


based on this reply

so example, have xml this

<parent_node >    <category>low</category>    <category>medium</category>    <category>high</category> </parent_node> 

and good. in case have default xml namespace here, xml looks this:

<parent_node xmlns="http://schemas.datacontract.org/2004/07/monitorwang.core.interfaces.entities">    <category>low</category>    <category>medium</category>    <category>high</category> </parent_node> 

and doesn't work.

entire script:

declare @xmlvariable xml = '<parent_node xmlns="http://schemas.datacontract.org/2004/07/monitorwang.core.interfaces.entities">                               <category>low</category>                               <category>medium</category>                               <category>high</category>                             </parent_node>'    select       xtbl.cats.value('.', 'varchar(50)')         @xmlvariable.nodes('/parent_node/category') xtbl(cats) 

please, advice, how fix it?

if want account default namespace throughout document can use like....

    declare @xmlvariable xml = '<parent_node xmlns="http://schemas.datacontract.org/2004/07/monitorwang.core.interfaces.entities">                               <category>low</category>                               <category>medium</category>                               <category>high</category>                             </parent_node>'    select       xtbl.cats.value('.', 'varchar(50)')         @xmlvariable.nodes('declare default element namespace "http://schemas.datacontract.org/2004/07/monitorwang.core.interfaces.entities"; /parent_node/category') xtbl(cats) 

alternatively, can declare namespace in xquery string , refer in xpath if default namespace on child element...

@xmlvariable.nodes('declare namespace c="http://schemas.datacontract.org/2004/07/monitorwang.core.interfaces.entities"; /parent_node/c:category') 

there more detail here.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -