sql server - TSQL querying xml with namespace -


i've been searching solution problem. want retrieve data xml column. here data:

<notification xmlns="http://model.company/notification/de/v1"      datenotification="2017-07-24t11:47:51.012+02:00"      identifiant="4b7330c7-021f-4cf9-ace6-f74d73f409ef"      personneid="1071249"      source="regles"      sourceversion="1.0.17"      typemouvement="modification">         <evenementde xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"              referenceoriginale="1071249"              xsi:type="changementsignaletique">                 <champ                      anciennevaleur="doe"                      nom="nom"                      nouvellevaleur="doe" />         </evenementde>         <evenementde xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"              referenceoriginale="1071249"              xsi:type="changementsignaletique">                 <champ                      anciennevaleur="john"                      nom="prenom"                      nouvellevaleur="john carl" />         </evenementde> </notification> 

i'd retrieve "anciennevaleur", "nouvellevaleur" specific "referenceoriginale". here's fiddler: fiddler getting attribute root easy, can't attributes champ.

i hope can me. in advance.

you must use proper xpath elements , attributes wish query/present.

declare @xml xml = n'... xml...';      xmlnamespaces (default 'http://model.company/notification/de/v1')   select      n.n.value('./champ[1]/@anciennevaleur', 'nvarchar(100)') [anciennevaleur] @xml.nodes('/notification/evenementde') n(n)  n.n.value('./@referenceoriginale', 'int') = 1071249 

... results ...

anciennevaleur doe john 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -