Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
 

Go Back   XSL - XML - RSS Forums > XML General > SQL and XML

Tags:



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-25-2008, 11:37 PM
Ganesh Muthuvelu
 
Posts: n/a

Default Shred XML Data into Columns/Rows



Hello,
I have a XML as below. As you may see, the ErrorMessage node has several
"Error" nodes with attributes and data. Now, I want to get those attribute
names as "columns" and the values in "rows".. (Action, Key, MultiRefId,
Batch... are the columns).

Can someone help me to get this using SQL Server XML capaiblities?. Thanks.


******************
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelo pe/">
<soap:Body>
<AddPartitionResponse xmlns="http://xyz.com/WebServices/">
<AddPartitionResult>
<Success>false</Success>
<NumberOfBatches>1</NumberOfBatches>
<NumberOfEntities>2</NumberOfEntities>
<RecordsAffected>0</RecordsAffected>
<XmlRequestID>169</XmlRequestID>
<ResponseMessage>Request executed but with errors</ResponseMessage>
<ErrorMessage>
<Error Action="AddPartition" Id="2" Key="MCL_12" MultiRefId="id2"
Batch="1/1" Status="Failed"
FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"
FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed </Error>
<Error Action="AddPartition" Id="1" Key="MCL_11" MultiRefId="id1"
Batch="1/1" Status="Failed"
FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"
FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed </Error>
</ErrorMessage>
</AddPartitionResult>
</AddPartitionResponse>
</soap:Body>
</soap:Envelope>
******************
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-26-2008, 12:14 PM
Joe Fawcett
 
Posts: n/a

Default Re: Shred XML Data into Columns/Rows

Are the attribute names fixed or could they change from Error to Error?

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"Ganesh Muthuvelu" <GaneshMuthuvelu@discussions.microsoft.com> wrote in
message news:E0EB427A-2988-4A06-942B-8060E37CD8C5@microsoft.com...
> Hello,
> I have a XML as below. As you may see, the ErrorMessage node has several
> "Error" nodes with attributes and data. Now, I want to get those attribute
> names as "columns" and the values in "rows".. (Action, Key, MultiRefId,
> Batch... are the columns).
>
> Can someone help me to get this using SQL Server XML capaiblities?.
> Thanks.
>
>
> ******************
> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:soap="http://schemas.xmlsoap.org/soap/envelo pe/">
> <soap:Body>
> <AddPartitionResponse xmlns="http://xyz.com/WebServices/">
> <AddPartitionResult>
> <Success>false</Success>
> <NumberOfBatches>1</NumberOfBatches>
> <NumberOfEntities>2</NumberOfEntities>
> <RecordsAffected>0</RecordsAffected>
> <XmlRequestID>169</XmlRequestID>
> <ResponseMessage>Request executed but with errors</ResponseMessage>
> <ErrorMessage>
> <Error Action="AddPartition" Id="2" Key="MCL_12" MultiRefId="id2"
> Batch="1/1" Status="Failed"
> FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"
> FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed </Error>
> <Error Action="AddPartition" Id="1" Key="MCL_11" MultiRefId="id1"
> Batch="1/1" Status="Failed"
> FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"
> FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed </Error>
> </ErrorMessage>
> </AddPartitionResult>
> </AddPartitionResponse>
> </soap:Body>
> </soap:Envelope>
> ******************



Reply With Quote
  #3 (permalink)  
Old 11-26-2008, 02:16 PM
Joe Fawcett
 
Posts: n/a

Default Re: Shred XML Data into Columns/Rows

If the attribute names are fixed then this might get you started:
DECLARE @Xml xml;

SET @Xml = '<soap:Envelope
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:soap="http://schemas.xmlsoap.org/soap/envelo pe/">

<soap:Body>

<AddPartitionResponse xmlns="http://xyz.com/WebServices/">

<AddPartitionResult>

<Success>false</Success>

<NumberOfBatches>1</NumberOfBatches>

<NumberOfEntities>2</NumberOfEntities>

<RecordsAffected>0</RecordsAffected>

<XmlRequestID>169</XmlRequestID>

<ResponseMessage>Request executed but with errors</ResponseMessage>

<ErrorMessage>

<Error Action="AddPartition" Id="2" Key="MCL_12" MultiRefId="id2"

Batch="1/1" Status="Failed"

FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"

FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed </Error>

<Error Action="AddPartition" Id="1" Key="MCL_11" MultiRefId="id1"

Batch="1/1" Status="Failed"

FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"

FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed </Error>

</ErrorMessage>

</AddPartitionResult>

</AddPartitionResponse>

</soap:Body>

</soap:Envelope>';

;WITH XMLNAMESPACES ('http://schemas.xmlsoap.org/soap/envelope/' as soap,

DEFAULT 'http://xyz.com/WebServices/')

SELECT

e.value('@Action', 'nvarchar(50)') [Action],

e.value('@Id', 'nvarchar(50)') [Id],

e.value('@Key', 'nvarchar(50)') [Key],

e.value('@MultiRefId', 'nvarchar(50)') [MultiRefId],

e.value('@Batch', 'nvarchar(50)') [Batch],

e.value('@Status', 'nvarchar(50)') [Status],

e.value('@FaultCodeNamespace', 'nvarchar(80)') [FaultCodeNamespace],

e.value('@FaultCodeException', 'nvarchar(80)') [FaultCodeException],

e.value('.', 'nvarchar(50)') [Message]

FROM
@Xml.nodes('/soap:Envelope/soap:Body/AddPartitionR esponse/AddPartitionResult/ErrorMessage/Error')
X(e);






--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name



"Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message
news:%238Z58w7TJHA.3648@TK2MSFTNGP05.phx.gbl...
> Are the attribute names fixed or could they change from Error to Error?
>
> --
>
> Joe Fawcett (MVP - XML)
>
> http://joe.fawcett.name
>
> "Ganesh Muthuvelu" <GaneshMuthuvelu@discussions.microsoft.com> wrote in
> message news:E0EB427A-2988-4A06-942B-8060E37CD8C5@microsoft.com...
>> Hello,
>> I have a XML as below. As you may see, the ErrorMessage node has several
>> "Error" nodes with attributes and data. Now, I want to get those
>> attribute
>> names as "columns" and the values in "rows".. (Action, Key, MultiRefId,
>> Batch... are the columns).
>>
>> Can someone help me to get this using SQL Server XML capaiblities?.
>> Thanks.
>>
>>
>> ******************
>> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:soap="http://schemas.xmlsoap.org/soap/envelo pe/">
>> <soap:Body>
>> <AddPartitionResponse xmlns="http://xyz.com/WebServices/">
>> <AddPartitionResult>
>> <Success>false</Success>
>> <NumberOfBatches>1</NumberOfBatches>
>> <NumberOfEntities>2</NumberOfEntities>
>> <RecordsAffected>0</RecordsAffected>
>> <XmlRequestID>169</XmlRequestID>
>> <ResponseMessage>Request executed but with
>> errors</ResponseMessage>
>> <ErrorMessage>
>> <Error Action="AddPartition" Id="2" Key="MCL_12"
>> MultiRefId="id2"
>> Batch="1/1" Status="Failed"
>> FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"
>> FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed
>> </Error>
>> <Error Action="AddPartition" Id="1" Key="MCL_11"
>> MultiRefId="id1"
>> Batch="1/1" Status="Failed"
>> FaultCodeNamespace="http://schemas.xmlsoap.org/soa p/envelope/"
>> FaultCodeException="Server.generalException">ERR_R EC_EXISTSFailed
>> </Error>
>> </ErrorMessage>
>> </AddPartitionResult>
>> </AddPartitionResponse>
>> </soap:Body>
>> </soap:Envelope>
>> ******************

>
>



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



Contact Us -|- XSL - XML - RSS Forums -|- Archive -|- Top -|-Rules/Disclaimer-|-Help/Support -|-Advertise
© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
All times are GMT. The time now is 12:02 PM.
Style Developed by Epic Designz