Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to generate xml file without headers and append it to the existing file using sql query.

What I have tried:

dalr = New SqlDataAdapter(sql, ldb.dbconnect)
dalr.Fill(Dslr)
Dslr.WriteXml("d:\a.xml")



In the above code it will generate xml file with headers and overwrites existing file.
Posted
Updated 4-Apr-18 5:18am
Comments
CHill60 4-Apr-18 9:10am    
What do you mean by "with headers"?
kgmmurugesh 4-Apr-18 9:48am    
<?xml version="1.0" standalone="true"?>

-<newdataset>


-

<xml_f52e2b61-18a1-11d1-b105-00805f49916b>


the above tag

1 solution

Okay, if you want to stick with the SqlDataAdapater you could just write to another file, remove the 'header' and combine the existing file with the new one.
Removing the header could be done with the following piece of Regex code:
VB
Dim ResultString As String
Try
	ResultString = Regex.Replace(SubjectString, "<\?xml[^>]+>(\r\n)?", "")
Catch ex As ArgumentException
	'Syntax error in the regular expression
End Try
A quick google let me to this page[^] for some info on concattenating files in Visual Basic
 
Share this answer
 
Comments
kgmmurugesh 5-Apr-18 0:50am    
OK, Is there any way to get the result by SQL query?
Christiaan van Bergen 5-Apr-18 1:28am    
Check out this article: https://stackoverflow.com/questions/18654157/how-to-make-sql-query-result-to-xml-file
kgmmurugesh 9-Apr-18 3:41am    
I use the following query in ssms, it will show the given result but I use this query in vb.net coding it will show different result. I want the ssms result.

select unit_name, Unit_PrintName from unit_table for xml path('customer'), root('erpimportdata')


<erpimportdata>
<customer>
<unit_name>Doz > & A
<unit_printname>Doz

<customer>
<unit_name>Abc
<unit_printname>Abc

<customer>
<unit_name>Zzzzzzzz
<unit_printname>Zzzzzzzz

<customer>
<unit_name>Nos
<unit_printname>Nos




RESULT OF VB.NET CODE.
<?xml version="1.0" standalone="yes"?>
<newdataset>

<xml_f52e2b61-18a1-11d1-b105-00805f49916b><erpimportdata><customer><unit_name>Doz &gt; &amp; A</unit_name><Unit_PrintName>Doz</Unit_PrintName></customer><customer><unit_name>Abc</unit_name><Unit_PrintName>Abc</Unit_PrintName></customer><customer><unit_name>Zzzzzzzz</unit_name><Unit_PrintName>Zzzzzzzz</Unit_PrintName></customer><customer><unit_name>Nos</unit_name><Unit_PrintName>Nos</Unit_PrintName></customer></erpimportdata>

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