[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 681
  • Last Modified:

sql server xquery: namespace parsing

Techies--
I want to extrapolate the values within the tags with xquery but the namespace issue and nil="true" stuff has been a battle.  What I've posted as the code obviously doesn't work-- please review and correct.

DECLARE @applog_msg xml;
SET @applog_msg = '
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.metrocloud.com/ServiceContracts/LogService/Metrocloud.Framework.Logging.LogService</Action>
  </s:Header>
  <s:Body>
    <LogException xmlns="http://www.metrocloud.com/ServiceContracts/LogService">
      <exceptionLog xmlns:d4p1="http://www.metrocloud.com/2012/09/Logging" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d4p1:ServiceDescription i:nil="true" />
        <d4p1:ServiceDomainName>TheServiceDomain</d4p1:ServiceDomainName>
        <d4p1:Type>AnyType</d4p1:Type>
      </exceptionLog>
    </LogException>
  </s:Body>
</s:Envelope>';


   SELECT
    T.c.value('d4p1:ServiceDescription[1] i:nil="true" />') as ServiceDescription,
    T.c.value('d4p1:ServiceDomainName[1]', 'varchar(100)') as ServiceDomainName,
    T.c.value('d4p1:Type[1]', 'varchar(10)') as [Type]
     FROM @applog_msg.nodes('LogException/exceptionLog') as T(c);
     
  

Open in new window

0
Paula DiTallo
Asked:
Paula DiTallo
1 Solution
 
Saurabh BhadauriaCommented:
Try like this....

DECLARE @applog_msg xml;
SET @applog_msg = '
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://www.metrocloud.com/ServiceContracts/LogService/Metrocloud.Framework.Logging.LogService</Action>
  </s:Header>
  <s:Body>
    <LogException xmlns="http://www.metrocloud.com/ServiceContracts/LogService">
      <exceptionLog xmlns:d4p1="http://www.metrocloud.com/2012/09/Logging" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <d4p1:ServiceDescription i:nil="true" />
        <d4p1:ServiceDomainName>TheServiceDomain</d4p1:ServiceDomainName>
        <d4p1:Type>AnyType</d4p1:Type>
      </exceptionLog>
    </LogException>
  </s:Body>
</s:Envelope>';

;WITH XMLNAMESPACES(
    'http://schemas.xmlsoap.org/soap/envelope/' AS s,
      'http://www.metrocloud.com/2012/09/Logging' as d4p1,
      'http://www.w3.org/2001/XMLSchema-instance' as i,
    DEFAULT 'http://www.metrocloud.com/ServiceContracts/LogService' 
    
)


   SELECT
    T.c.value('d4p1:ServiceDescription[1]/@i:nil','varchar(100)') as ServiceDescription,
    T.c.value('d4p1:ServiceDomainName[1]', 'varchar(100)') as ServiceDomainName,
    T.c.value('d4p1:Type[1]', 'varchar(10)') as [Type]
     FROM @applog_msg.nodes('s:Envelope/s:Body/LogException/exceptionLog') as T(c);
     
  

Open in new window

0
 
Paula DiTalloIntegration developerAuthor Commented:
Brilliantly done! Thank you!
0

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now