繁体   English   中英

使用带有嵌套名称空间的SQL Server 2012从XML中选择值

[英]Selecting values out of XML with SQL Server 2012 with nested namespaces

我的XML看起来像

<?xml version="1.0" encoding="UTF-8"?>
<ListasExternasFull xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <Encabezado xmlns="http://tempuri.org/">
      <Acceso>true</Acceso>
      <Usuario>FENALCO</Usuario>
      <Contrasena>FENALCO2015PROD</Contrasena>
      <Documento>24944511</Documento>
      <TipoDocumento>1</TipoDocumento>
      <Nombres />
      <Apellidos />
      <Login />
      <Fecha>2016-01-23T17:07:56.1986626-05:00</Fecha>
      <IdConsulta>0</IdConsulta>
   </Encabezado>
   <objContraloria xmlns="http://tempuri.org/">
      <Id>92798</Id>
      <IsContraloria>false</IsContraloria>
      <Cedula>24944511</Cedula>
      <Nombre />
      <Departamento />
      <Municipio />
      <EntidadAfectada />
      <FallosACargo />
      <TipoResponsabilidad />
      <TipoPersona />
      <ReportadoPor />
      <FechaControl>2016-01-23T17:03:43.13</FechaControl>
      <Excepcion />
   </objContraloria>
   <objFosyga xmlns="http://tempuri.org/">
      <Id>92496</Id>
      <IsFosyga>false</IsFosyga>
      <NumeroIdentidad>24944511</NumeroIdentidad>
      <Nombre />
      <Apellido />
      <Departamento />
      <Municipio />
      <Estado />
      <Entidad />
      <Regimen />
      <FechaAfiliacion />
      <TipoAfiliado />
      <FechaControl>2016-01-23T17:07:56.285612-05:00</FechaControl>
      <Excepcion>Se generó un error al consultar la lista. Por favor intente mas tarde o contacte a su administrador.</Excepcion>
   </objFosyga>
   <objOfac xmlns="http://tempuri.org/">
      <Id>91950</Id>
      <Cedula>24944511</Cedula>
      <Nombre />
      <Direccion />
      <Tipo />
      <Programa />
      <Score />
      <FechaControl>2016-01-23T17:03:43.097</FechaControl>
      <Lista />
      <Excepcion />
      <IsOfac>false</IsOfac>
   </objOfac>
   <objPolicia xmlns="http://tempuri.org/">
      <Id>93113</Id>
      <Cedula>24944511</Cedula>
      <Nombre />
      <IsAntecedentes>false</IsAntecedentes>
      <IsRegistrado>false</IsRegistrado>
      <Mensaje />
      <FechaControl>2016-01-23T17:08:17.3118339-05:00</FechaControl>
      <IsPolicia>false</IsPolicia>
      <Excepcion>Se generó un error al consultar la lista. Por favor intente mas tarde o contacte a su administrador.</Excepcion>
   </objPolicia>
   <objRues xmlns="http://tempuri.org/">
      <Id>91297</Id>
      <TipoID />
      <Nit>24944511</Nit>
      <RazonSocial />
      <Descripcion_Camara />
      <Descripcion_Categoria_Matricula />
      <Fecha_Matricula />
      <IsRM>false</IsRM>
      <IsRUP>false</IsRUP>
      <IsESAL>false</IsESAL>
      <IsRNT>false</IsRNT>
      <FechaControl>2016-01-23T17:03:43.473</FechaControl>
      <IsRUES>false</IsRUES>
      <Excepcion />
   </objRues>
   <objSim xmlns="http://tempuri.org/">
      <Id>92657</Id>
      <Cedula>24944511</Cedula>
      <NoRadicado />
      <Identificador />
      <FechaSolicitud />
      <Estado />
      <Resultado />
      <DisponibleEntrega />
      <Excepcion />
      <FechaControl>2016-01-23T17:03:43.207</FechaControl>
      <IsSim>false</IsSim>
   </objSim>
   <objSimit xmlns="http://tempuri.org/">
      <Id>92905</Id>
      <Cedula>24944511</Cedula>
      <Infractor />
      <Resolucion />
      <FechaResolucion />
      <Comparendo />
      <FechaComparendo />
      <Secretaria />
      <Estado />
      <Infraccion />
      <ValorMulta />
      <InteresMora />
      <ValorAdicional />
      <ValorPagar />
      <FechaControl>2016-01-23T17:03:43.55</FechaControl>
      <IsSimit>false</IsSimit>
      <Excepcion />
   </objSimit>
   <objSisben xmlns="http://tempuri.org/">
      <Id>94783</Id>
      <IsSisben>true</IsSisben>
      <NumeroDocumento>24944511</NumeroDocumento>
      <Nombres>MARIA ISLENY</Nombres>
      <Apellidos>RODAS DE FRANCO</Apellidos>
      <TipoDocumento>Cédula de Ciudadanía</TipoDocumento>
      <Departamento>RISARALDA</Departamento>
      <Municipio>PEREIRA</Municipio>
      <Area>1</Area>
      <Ficha>10097</Ficha>
      <Puntaje>47,86</Puntaje>
      <FechaModificacion>2015/03/05</FechaModificacion>
      <Estado>VALIDADO</Estado>
      <FechaControl>2016-01-23T17:03:43.287</FechaControl>
      <Excepcion />
   </objSisben>
   <objRuaf xmlns="http://tempuri.org/">
      <Id>84066</Id>
      <IsRuaf>true</IsRuaf>
      <TipoIdentificacion>CC</TipoIdentificacion>
      <Identificacion>24944511</Identificacion>
      <Nombre>MARIA ISLENY RODAS DE FRANCO</Nombre>
      <Sexo>FEMENINO</Sexo>
      <UbicacionAfiliacion>RISARALDA - PEREIRA</UbicacionAfiliacion>
      <EstadoAfiliado>ACTIVO</EstadoAfiliado>
      <Administradora>NUEVA EPS SA</Administradora>
      <Regimen>SALUD: CONTRIBUTIVO</Regimen>
      <FechaAfiliacion>2015-08-01</FechaAfiliacion>
      <TipoAfiliado>BENEFICIARIO</TipoAfiliado>
      <FechaControl>2016-01-23T17:03:45.207</FechaControl>
      <Observacion />
      <Excepcion />
   </objRuaf>
   <objDisponibilidad xmlns="http://tempuri.org/">
      <Fosyga>true</Fosyga>
      <Sisben>true</Sisben>
      <Ofac>true</Ofac>
      <Policia>true</Policia>
      <Rues>true</Rues>
      <Sim>true</Sim>
      <Simit>true</Simit>
      <Contraloria>true</Contraloria>
      <Onu>true</Onu>
      <Ruaf>true</Ruaf>
   </objDisponibilidad>
</ListasExternasFull>

由于嵌套的命名空间aguin而无法到达objRuaf / Identificacion节点,我可以通过查询来帮助您到达这些节点

WITH XMLNAMESPACES (DEFAULT 'http://tempuri.org/')声明默认的XML名称空间:

;WITH XMLNAMESPACES (DEFAULT 'http://tempuri.org/')
SELECT val = s.c.value('.', 'NVARCHAR(100)') 
FROM @x.nodes('//objRuaf/Identificacion') AS s(c);

LiveDemo


要么:

;WITH XMLNAMESPACES ('http://tempuri.org/' AS a)
SELECT val = s.c.value('.', 'NVARCHAR(100)') 
FROM @x.nodes('//a:objRuaf/a:Identificacion') AS s(c)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM