Click here to Skip to main content
15,920,896 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in the output i am having that new dataset tag.I have to remove this tag
the current output is
XML
<NewDataSet>
<Table>
</Table>
<Table>
</Table>
...
</NewDataSet>

But i need the output in the following format
XML
<Table>
</Table>
<Table>
</Table>

Because when client is loadind my web service output with their SOAP UI tool this NewDataset creats one blank node like <newdataset xmlns="">.
This causes problem to import the data through web service.
Now i have to remove the NewDataset tag from my end.
check the below code:
C#
string temp1 = DS.GetXml();//DS is dataset
           myDatas.LoadXml(temp1);
           string temp = myDatas.FirstChild.InnerXml;
           XmlNode node = myDatas.ParentNode;
           myDatas1.LoadXml(temp);

But the problem is that Load xml works for only single
<Table></Table>
..else it throws multiple root error..please help me in this problem..wht to do with that new dataset thing!
Posted
Updated 19-Oct-10 1:39am
v3

1 solution

The problem is that when you follow XML rules it is mandatory to have a single root element. But when you would really like to lose it, the most straight way would be to replace "</NewDataSet>" and "<NewDataSet>" with "". It would be better to use methods like IndexOf and LastIndexOf to remove it.

http://msdn.microsoft.com/en-us/library/7wtc81z6.aspx[^]

Good luck!
 
Share this answer
 
Comments
Sugato Pal 19-Oct-10 7:27am    
can you please tell me how to use replace in c sharp code..actually my output has to be in xml format..it can not be string..can u suggest something..
E.F. Nijboer 19-Oct-10 10:44am    
The replace goes something like String.Replace("", string.Empty)
Furthermore you can see in your own code that xml is nothing more than a string.
Your own line of code -> string temp1 = DS.GetXml();//DS is dataset
Sugato Pal 20-Oct-10 8:12am    
yes but in that case the output ll be string bt i want my output in XML doc format and there should not be any New Dataset tag..plz help me i'm running out of time
E.F. Nijboer 21-Oct-10 11:59am    
If you do String.Replace("<NewDataSet>", string.Empty) the only thing that is removed is the NewDataSet element. I do not fully understand what is not XML doc format about that (except the fact that it has multiple root elements and therefore not following xml rules)

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