Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I need to read xml file and those tag inside it, i need data for those tag.
837 is the claim file format in xml.

<a1>456
<b1>456
<g1>456

What I have tried:

I have created different SP for find different tags and insert into different tables as per tags.
Posted
Updated 6-Jan-22 20:55pm
Comments
0x01AA 6-Jan-22 12:38pm    
"I have created different SP for find different tags and insert into different tables as per tags.": And what is the problem?
Member 11776570 6-Jan-22 12:46pm    
there are too mach SP for each tag, so SP call another SP and another SP call another. That the problem. Then all the table we merge into 1 table.
0x01AA 6-Jan-22 12:49pm    
I don't see any problem to read N xml files and insert the desired data into a database. But of course, that's just hard work.

[Edit]
Thinking again about it, not even hard work: Import them 'raw' into a temporary table (should be easy with MSSQL). After this you can process the data with SQL.

1 solution

You don't need to use SPs for this purpose. SQL Server provides default support in querying XML Documents.

Below is the query that you can use in your case

DECLARE @XML XML

Set @XML ='<ROOT><a1>456</a1><b1>457</b1><g1>458</g1></ROOT>'

Select 
      Code       = lvl1.n.value('local-name(.)','nvarchar(max)') 
      ,Name       = lvl1.n.value('text()[1]','nvarchar(max)') 
 From  @XML.nodes('ROOT/*')  lvl1(n)


You can also find a similar problem along with its solution
sql server - Select all XML nodes from XML column - Stack Overflow[^]
 
Share this answer
 
v2
Comments
Member 11776570 7-Jan-22 9:13am    
okay and if i want to read inside the tag then, like below is the tag.

<hierarchicalloop loopid="2000A" loopname="abc efg" id="1" parentid="">

I need to read loopid and loopname value from it then what to do now ?
_Asif_ 10-Jan-22 0:24am    
We have given you a direction to start. All you need to do now is to do some experiment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900