Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Append datarow to the end of an xml file

Posted on 2004-10-19
8
Medium Priority
?
923 Views
Last Modified: 2012-08-14
I am writing in VB.NET and working with an ADO.NET dataset.

In most cases I can use the dataSet.WriteXML method to backup my dataset as an xml file.  But for the most part I don't want to have to rewrite the xml file everytime I add a new row to the dataset.  How would I go about appending just the new row data to the end of the xml file or do I just have to rewrite it everytime?
0
Comment
Question by:misslinda454
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Expert Comment

by:rdcpro
ID: 12352834
You can use the GetChanges method:

changedDataSet = myDataSet.GetChanges(DataRowState.Modified)

then write the changedDataSet to an XML document.  If there's only a single row in it, you can then append the appropriate node to the previous XML document.  Otherwise you'd have to iterate over the changed nodes, appending each one.  Not sure if that saves you anything, though, unless the data is very large and you keep the original XML in memory.

Regards,
Mike Sharp
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 12355440
J_Make sorry, i've missed it, it's all right with your Schema
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 12355442
upppssss....wrong topic, sorry guys ;)
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:misslinda454
ID: 12357602
Would you happen to have an example of appending a datarow to the data set?  Does this recognize the schema for you or do you have to take each field and know the schema?  If you use the get changes method are you still only writing the changed rows or are you still re-writing the whole xml doc .. if it only goes through and writes the changes that would be perfect!
0
 
LVL 26

Expert Comment

by:rdcpro
ID: 12361154
Well, MSDN has this example:

Private Sub UpdateDataSet(ByVal myDataSet As DataSet)
   ' Check for changes with the HasChanges method first.
   If Not myDataSet.HasChanges(DataRowState.Modified) Then Exit Sub
   ' Create temporary DataSet variable.
   Dim xDataSet As DataSet
   ' GetChanges for modified rows only.
   xDataSet = myDataSet.GetChanges(DataRowState.Modified)
   ' Check the DataSet for errors.
   If xDataSet.HasErrors Then
      ' Insert code to resolve errors.
   End If
   ' After fixing errors, update the data source with the DataAdapter
   ' used to create the DataSet.
   myOleDbDataAdapter.Update(xDataSet)
End Sub


Regards,
Mike Sharp
0
 

Author Comment

by:misslinda454
ID: 12361294
I knew how to update a DB using a data adapter and dataset ... I didn't know how to add a row to the xml document  .. I know how to append a child node at a time just not a row - a collection of nodes for lack of better words ..

So if I had a row that had data in Field1, Field2, Field3 .. and I wanted to add that row to the bottom of the data set with a doc that looked like ..

<datatable1>
   <row>
     <field1> a </field1>
     <field2> b </field2>
     <field3> c </field3>
   </row>
   .....how to append next  row to end?????
</datatable>

0
 
LVL 26

Accepted Solution

by:
rdcpro earned 500 total points
ID: 12362142
Oh, I see.  In order to append a row, just append the parent node.  In your example, appending a new <row> will attach it, along with it's descendants.  But before that point, when you copy the node (or import it) you set a boolean value to define whether you want a deep copy or not.  Deep, meaning the node and it's descendants.  But the operation of appending is otherwise the same.

Here's an example of Importing nodes from one XML to another.  It's written in C#, but the VB approach is similar, except for syntactical differences.  In .NET, you can't simply append nodes from one document to another.  But you can create nodes using methods of the XmlDocument class, and append them to the same instance of the class.  

http://rdcpro.com/Members/rdcpro/snippets/importnode/

A javascript example, using MSXML, that clones or moves nodes is found here:

http://rdcpro.com/Members/rdcpro/snippets/moveorclone/

Regards,
Mike Sharp
0
 

Author Comment

by:misslinda454
ID: 12362178
Perfect! Thank you very much!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question