Solved

sql server xquery: namespace parsing

Posted on 2012-12-20
2
569 Views
Last Modified: 2012-12-21
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
Comment
Question by:ditallop
2 Comments
 
LVL 12

Accepted Solution

by:
Saurabh Bhadauria earned 500 total points
Comment Utility
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
 

Author Comment

by:ditallop
Comment Utility
Brilliantly done! Thank you!
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now