SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Read all values from an xml node


Read all values from an xml node

Author
Message
kumar-378458
kumar-378458
SSC-Enthusiastic
SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)

Group: General Forum Members
Points: 114 Visits: 72
Hi All,
I have the following code and trouble reading values of Bank Accounts. If i remove the line it says "xmlns="http://applications.apch1.com/webservice/schema/" then i my query is working. But i cant remove this becasue that is what i will get response from a web service. All the records are stored in the database with this line included. Please help. Also please specify if there is any easy way to read these values.


DECLARE @MyXML XML
SET @MyXML = '<GetEmployeeDetails xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<return xmlns="http://applications.apch1.com/webservice/schema/">
<CustomerID> A8339 </CustomerID>
<BankAccounts>
<BankAccount>123456</BankAccount>
<BankAccount>7890123</BankAccount>
</BankAccounts>
</return>
</GetEmployeeDetails>'

SELECT
pref.value('./text()[1]', 'varchar(MAX)') AS 'BankAccount'
FROM @MyXML.nodes('//GetEmployeeDetails/return/BankAccounts/child::node()') AS RequestXml(pref)
where pref.value('local-name(.)[1]', 'varchar(100)') ='BankAccount'



Thanks,
Kum
LutzM
LutzM
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23955 Visits: 13559
You could ignore the namespace by using a pseudo-namespace and a * to name all namespaces:
;
WITH XMLNAMESPACES(DEFAULT 'some_string')
SELECT
pref.value('./text()[1]', 'varchar(MAX)') AS 'BankAccount'
FROM @MyXML.nodes('//*:GetEmployeeDetails/*:return/*:BankAccounts/child::node()') AS RequestXml(pref)
where pref.value('local-name(.)[1]', 'varchar(100)') ='BankAccount'





Lutz
A pessimist is an optimist with experience.

How to get fast answers to your question
How to post performance related questions
Links for Tally Table , Cross Tabs and Dynamic Cross Tabs , Delimited Split Function
kumar-378458
kumar-378458
SSC-Enthusiastic
SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)SSC-Enthusiastic (114 reputation)

Group: General Forum Members
Points: 114 Visits: 72
Thank you LutzM.

Can you also tell me how to get the CustomerID in the resultset ?
SO the output should looks like:
A8339 123456
A8339 7890123

Thank you all.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search