Multiple tags with same name in XML

whizkid123

Active member
Joined
Dec 11, 2002
Messages
33
Location
India
Hi all! Im creating an XML file with data populated from my database. Till now I have been successful in creating the file. But now the problem is, if the table has more than 1 record for the particular Id, then instead of overwriting the XML file with the latest record, as it is happening now, it should create a seperate tag without overwriting the existing tag. Ive tried to use arrays while declaring the items in the collection but of no
help. How can this be accomplished?? Thanx!
 
What does your XML look like? Could you possibly use the DataSets GetXml() method? Or use the GetXml() method and apply a transform?

I think the problem may be in your code so youll have to post the relevant parts. Theres nothing wrong with having more than one node with the same name in XML.

-ner
 
Well Im not using the datasets getxml method for creating this xml file. Im attaching the project from which Ive taken the idea of writing to XML. In my project, instead of taking values from the user, Im picking it up from the database.

You were mentioning something about dataset and creating an XML from that. What is it? Is it simpler than the one above? If yes, can you please explain as I have recently migrated to .Net and have no idea about it. Thanx!
 

Attachments

All XML files must have a root node. You can add one like this (it doesnt have to be named Root):
Code:
<?xml version="1.0"?>
<Root>
<Address xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <FirstName>dan</FirstName>
  <LastName>jones</LastName>
  <CompanyName />
  <Address1 />
  <Address2 />
  <City />
  <Region />
  <PostalCode />
  <Country />
  <Email />
</Address>
</Root>

An alternative is to use a DataSet. You can create a new DataSet through .NETs designer window. Define the fields and save it as an XSD. You can create a DataSet from this somehow (Im not sure offhand, but I know its possible). Once you have your DataSet, youre home free. You can add, update, and delete rows. You can also Bind your controls directly to it or display a grid. To save the data, use the WriteXml method of the DataSet, which saves the data and the schema. You can also use ReadXml to get it back off the disk.

Good Luck!

-Nerseus
 
After you mentioned dataset, I was looking around for more help on that and came around component designer for creating one. Now what the problem is that it is not enabled. I read that I have to create an dataadapter and then select that and click on component designer, but it is not just geting enabled. Can you please tell me how do I get it enabled?

Ive tried both in code view & design view.
 
Back
Top