Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all! I'm 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. I've tried to use arrays while declaring the items in the collection but of no

help. How can this be accomplished?? Thanx!

  • *Experts*
Posted

What does your XML look like? Could you possibly use the DataSet's GetXml() method? Or use the GetXml() method and apply a transform?

 

I think the problem may be in your code so you'll have to post the relevant parts. There's nothing wrong with having more than one node with the same name in XML.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

Well I'm not using the dataset's getxml method for creating this xml file. I'm attaching the project from which I've taken the idea of writing to XML. In my project, instead of taking values from the user, I'm 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!

address book.zip

  • *Experts*
Posted

All XML files must have a root node. You can add one like this (it doesn't have to be named Root):

<?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 .NET's designer window. Define the fields and save it as an XSD. You can create a DataSet from this somehow (I'm not sure offhand, but I know it's possible). Once you have your DataSet, you're 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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

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?

 

I've tried both in code view & design view.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...