Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Shred XML Data into Columns/Rows

 
   Database Help (Home) -> XML RSS
Next:  Getting another employee's data from the Employee..  
Author Message
Ganesh Muthuvelu

External


Since: May 21, 2008
Posts: 5



(Msg. 1) Posted: Tue Nov 25, 2008 3:30 pm
Post subject: Shred XML Data into Columns/Rows
Archived from groups: microsoft>public>sqlserver>xml (more info?)

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/envelope/">
<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/soap/envelope/"
FaultCodeException="Server.generalException">ERR_REC_EXISTSFailed </Error>
<Error Action="AddPartition" Id="1" Key="MCL_11" MultiRefId="id1"
Batch="1/1" Status="Failed"
FaultCodeNamespace="http://schemas.xmlsoap.org/soap/envelope/"
FaultCodeException="Server.generalException">ERR_REC_EXISTSFailed </Error>
</ErrorMessage>
</AddPartitionResult>
</AddPartitionResponse>
</soap:Body>
</soap:Envelope>
******************

 >> Stay informed about: Shred XML Data into Columns/Rows 
Back to top
Login to vote
Joe Fawcett

External


Since: Jan 19, 2008
Posts: 38



(Msg. 2) Posted: Wed Nov 26, 2008 7:26 am
Post subject: Re: Shred XML Data into Columns/Rows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name

"Ganesh Muthuvelu" wrote in
message
> 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/envelope/">
> <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/soap/envelope/"
> FaultCodeException="Server.generalException">ERR_REC_EXISTSFailed </Error>
> <Error Action="AddPartition" Id="1" Key="MCL_11" MultiRefId="id1"
> Batch="1/1" Status="Failed"
> FaultCodeNamespace="http://schemas.xmlsoap.org/soap/envelope/"
> FaultCodeException="Server.generalException">ERR_REC_EXISTSFailed </Error>
> </ErrorMessage>
> </AddPartitionResult>
> </AddPartitionResponse>
> </soap:Body>
> </soap:Envelope>
> ******************

 >> Stay informed about: Shred XML Data into Columns/Rows 
Back to top
Login to vote
Joe Fawcett

External


Since: Jan 19, 2008
Posts: 38



(Msg. 3) Posted: Wed Nov 26, 2008 8:25 am
Post subject: Re: Shred XML Data into Columns/Rows [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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/envelope/">

<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/soap/envelope/"

FaultCodeException="Server.generalException">ERR_REC_EXISTSFailed </Error>

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

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

FaultCodeNamespace="http://schemas.xmlsoap.org/soap/envelope/"

FaultCodeException="Server.generalException">ERR_REC_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/AddPartitionResponse/AddPartitionResult/ErrorMessage/Error')
X(e);






--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name



"Joe Fawcett" wrote in message

> Are the attribute names fixed or could they change from Error to Error?
>
> --
>
> Joe Fawcett (MVP - XML)
>
> http://joe.fawcett.name
>
> "Ganesh Muthuvelu" wrote in
> message
>> 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/envelope/">
>> <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/soap/envelope/"
>> FaultCodeException="Server.generalException">ERR_REC_EXISTSFailed
>> </Error>
>> <Error Action="AddPartition" Id="1" Key="MCL_11"
>> MultiRefId="id1"
>> Batch="1/1" Status="Failed"
>> FaultCodeNamespace="http://schemas.xmlsoap.org/soap/envelope/"
>> FaultCodeException="Server.generalException">ERR_REC_EXISTSFailed
>> </Error>
>> </ErrorMessage>
>> </AddPartitionResult>
>> </AddPartitionResponse>
>> </soap:Body>
>> </soap:Envelope>
>> ******************
>
>
 >> Stay informed about: Shred XML Data into Columns/Rows 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Different ways to shred xml data into defined columns - Looking for an expert's thoughts on two different ways to shred XML into defined columns (same record with XML and defined columns). (Much like Buehler's post a few days ago.) BOTH use an XML Map table, identifying: * a Fieldname to get the data, and.....

remote SP to shred local XML file - SQL Server 2005 I have an XML file and I'm using a stored procedure to shred it into tables. Works perfectly so long as the file is on the server. What I want to do is have an Excel file with VBA call the procedure on a remote SQL Server, and have the...

cdata all columns automatically - I have an application that is extremely dynamic. Users can type in their own sql statements and run queries however they want. Is there a way using SQL to automaticall wrap all the columns with a CDATA notation? EX: Query SELECT field1,..

Compare 2 XML Columns - Hi all: I have a table with 2 XML type columns of the same structure. How do I compare these 2 columns and return the difference? For example, here are some sample data in the two xml columns: xmlcol1 xmlcol2 <r1> ...

How to write binary data in xml - I am using dom object to writing xml document, but I didn't enter binary data. I have tried using <base64> , <bin.hex> but didn't find the solution. If u have an idea, reply me its a highly apprietaiatable
   Database Help (Home) -> XML All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]