R
richardkreidl
I want to be able to delete and search for elements in a XML file, I'm
using the code below for adding elements which works great:
Public Sub cmdAddElement_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdAddElement.Click
Dim doc As New XmlDocument
doc.Load("c:UMZ.xml")
Dim root As XmlNode = doc.DocumentElement
Dim EleName As XmlElement = doc.CreateElement("Name")
Dim ElePreMVS As XmlElement = doc.CreateElement("PreMVS")
Dim ElePostMVS As XmlElement = doc.CreateElement("PostMVS")
Dim ElePreCS As XmlElement = doc.CreateElement("PreCS")
Dim ElePostCS As XmlElement = doc.CreateElement("PostCS")
Dim EleMisc As XmlElement = doc.CreateElement("Misc")
EleName.InnerText = txtName.Text
ElePreMVS.InnerText = txtPreMVS.Text
ElePostMVS.InnerText = txtPostMVS.Text
ElePreCS.InnerText = txtPreCS.Text
ElePostCS.InnerText = txtPostCS.Text
EleMisc.InnerText = txtMisc.Text
root.AppendChild(EleName)
root.AppendChild(ElePreMVS)
root.AppendChild(ElePostMVS)
root.AppendChild(ElePreCS)
root.AppendChild(ElePostCS)
root.AppendChild(EleMisc)
doc.Save("c:UMZ.xml")
End Sub
So, basically the XML file could dynamically grow or shrink with
elements as they're added or deleted.
Here is the XML file with one element row:
<?xml version="1.0" standalone="yes"?>
<UMZ>
<Name>some text</Name>
<PreMVS>some text</PreMVS>
<PostMVS>some text</PostMVS>
<PreCS>some text</PreCS>
<PostCS>some text</PostCS>
<Misc>some text</Misc>
</UMZ>
Here is a blank XML file without any rows:
<?xml version="1.0" standalone="yes"?>
<UMZ>
</UMZ>
Here is the XML file with two element rows:
<?xml version="1.0" standalone="yes"?>
<UMZ>
<Name>some text</Name>
<PreMVS>some text</PreMVS>
<PostMVS>some text</PostMVS>
<PreCS>some text</PreCS>
<PostCS>some text</PostCS>
<Misc>some text</Misc>
<Name>some more text</Name>
<PreMVS>some more text</PreMVS>
<PostMVS>some more text</PostMVS>
<PreCS>some more text</PreCS>
<PostCS>some more text</PostCS>
<Misc>some more text</Misc>
</UMZ>
Then I would need another button that would search for a 'Name' of a
element in the XML file that I would specify and populate the
cooresponding textboxes. Then I could delete the element from the XML
if so desired with a delete button.
using the code below for adding elements which works great:
Public Sub cmdAddElement_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdAddElement.Click
Dim doc As New XmlDocument
doc.Load("c:UMZ.xml")
Dim root As XmlNode = doc.DocumentElement
Dim EleName As XmlElement = doc.CreateElement("Name")
Dim ElePreMVS As XmlElement = doc.CreateElement("PreMVS")
Dim ElePostMVS As XmlElement = doc.CreateElement("PostMVS")
Dim ElePreCS As XmlElement = doc.CreateElement("PreCS")
Dim ElePostCS As XmlElement = doc.CreateElement("PostCS")
Dim EleMisc As XmlElement = doc.CreateElement("Misc")
EleName.InnerText = txtName.Text
ElePreMVS.InnerText = txtPreMVS.Text
ElePostMVS.InnerText = txtPostMVS.Text
ElePreCS.InnerText = txtPreCS.Text
ElePostCS.InnerText = txtPostCS.Text
EleMisc.InnerText = txtMisc.Text
root.AppendChild(EleName)
root.AppendChild(ElePreMVS)
root.AppendChild(ElePostMVS)
root.AppendChild(ElePreCS)
root.AppendChild(ElePostCS)
root.AppendChild(EleMisc)
doc.Save("c:UMZ.xml")
End Sub
So, basically the XML file could dynamically grow or shrink with
elements as they're added or deleted.
Here is the XML file with one element row:
<?xml version="1.0" standalone="yes"?>
<UMZ>
<Name>some text</Name>
<PreMVS>some text</PreMVS>
<PostMVS>some text</PostMVS>
<PreCS>some text</PreCS>
<PostCS>some text</PostCS>
<Misc>some text</Misc>
</UMZ>
Here is a blank XML file without any rows:
<?xml version="1.0" standalone="yes"?>
<UMZ>
</UMZ>
Here is the XML file with two element rows:
<?xml version="1.0" standalone="yes"?>
<UMZ>
<Name>some text</Name>
<PreMVS>some text</PreMVS>
<PostMVS>some text</PostMVS>
<PreCS>some text</PreCS>
<PostCS>some text</PostCS>
<Misc>some text</Misc>
<Name>some more text</Name>
<PreMVS>some more text</PreMVS>
<PostMVS>some more text</PostMVS>
<PreCS>some more text</PreCS>
<PostCS>some more text</PostCS>
<Misc>some more text</Misc>
</UMZ>
Then I would need another button that would search for a 'Name' of a
element in the XML file that I would specify and populate the
cooresponding textboxes. Then I could delete the element from the XML
if so desired with a delete button.