Question : vb.net XML edit in form..

Hello.. I have some problem. Start from the beginning..

I have XML-File


looks like this...


<?xml version="1.0" encoding="utf-8"?>
<tagdata>
  <readopcvalues>
    <value opctag="TEST.AI_Weight_KL3" />
    <value opctag="TEST._produktion" />
    <value opctag="SystemVariables.ServerTime" />
  </readopcvalues>
</tagdata>



What I would like to do first is have the change to add some new tags to my taglist..

tex. add this..

<value opctag="TEST.Goood" />


<?xml version="1.0" encoding="utf-8"?>
<tagdata>
  <readopcvalues>
    <value opctag="TEST.AI_Weight_KL3" />
    <value opctag="TEST._produktion" />
    <value opctag="SystemVariables.ServerTime" />
    <value opctag="TEST.Goood" />
  </readopcvalues>
</tagdata>




I have done this with this code but dosent get really waht I want.. The problem is that I always starts a new nodes and not write in the old one...

look


<?xml version="1.0" encoding="utf-8"?>
<tagdata>
  <readopcvalues>
    <value opctag="TEST.AI_Weight_KL3" />
    <value opctag="TEST._produktion" />
    <value opctag="SystemVariables.ServerTime" />
   </readopcvalues>
  <value opctag="TEST.Goood" />
</tagdata>




This is the code...

   '-- Declare local variable and load xml file
        Dim doc2 As New XmlDocument()
        doc2.Load("XML\TagData.xml")

        '-- Create a new node and add it to the document.
        Dim newline As XmlElement = doc2.CreateElement("value")

        newline.SetAttribute("opctag", "PLC.Beijer_Agnesberg.OP_Dagens_produktion")

        doc2.DocumentElement.AppendChild(newline)
        '-- Save the xml file with the new changes.
        doc2.Save("XML\TagData.xml")



Please give me some tips.. My follow question is that I wolud like to show the Whole XML lines in textboxes..
like this.

textbox1.text =  <value opctag="TEST.Goood" />
textbox2.text =    <value opctag="TEST.AI_Weight_KL3" />

Why I want this it´s because I wolud like to edit the old line.. or add a new line.. or remove one..
I hope someone understand! But first we take the easy party to write in the same nod! :D

//Kavvis

Answer : vb.net XML edit in form..

Try this.

Arun
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Private Shared Sub RemoveXmlNode()
	Dim xmlPath As String = "C:\Arun\Projects\ConsoleTest\ConsoleTest\Response.xml"

	Dim dataSet As New DataSet()
	dataSet.ReadXml(xmlPath)
	dataSet.AcceptChanges()
	' <value opctag="TEST.Goood" />

	For i As Integer = 0 To dataSet.Tables("value").Rows.Count - 1
		If dataSet.Tables("value").Rows(i)("opctag").Equals("Test.Gooood") Then
			dataSet.Tables("value").Rows(i).Delete()
			dataSet.Tables("value").Rows(i).AcceptChanges()
		End If
	Next

	dataSet.WriteXml(xmlPath, XmlWriteMode.IgnoreSchema)
End Sub
Random Solutions  
 
programming4us programming4us