Jose_Cabrero
asked on
How to rewrite a XML vb.NET
Hi Guys I have this function for write a XML file but I dont know how to rewrite the same file could anybody show me how to do this
Private Sub createXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ensalada_btn.Click
Try
'Initialize a XmlTextWrite Object
Dim xmlDoc As XmlDocument
'Instantiate an xmlDocument
xmlDoc = New XmlDocument
'Create a XmlDeclaration & append Declaration
Dim xmlDec As XmlDeclaration = xmlDoc.CreateXmlDeclaratio n("1.0", Nothing, "no")
xmlDoc.AppendChild(xmlDec)
'Create a root Element
Dim rootElement As XmlElement = xmlDoc.CreateElement("Tran saccion_Te mp", Nothing)
'Create First Level
Dim elementLevelOne As XmlElement = xmlDoc.CreateElement("Orde r", Nothing)
elementLevelOne.SetAttribu te("id", "1")
Dim hsAttr As New Hashtable
hsAttr.Add("badge", "1235")
hsAttr.Add("date", "2004/08/03")
elementLevelOne.AppendChil d(myElemen t(xmlDoc, "Worker", "595893", hsAttr))
rootElement.AppendChild(el ementLevel One)
xmlDoc.AppendChild(rootEle ment)
xmlDoc.Save("c:/test1.xml" )
Catch ex As XmlException
MsgBox(ex.Message)
End Try
End Sub
Function myElement(ByVal xmlDocument As XmlDocument, ByVal ElementName As String, ByVal elementString As String, ByVal htAttr As Hashtable) As XmlElement
'Add Element & Attributes to a XML Element
Dim objElement As XmlElement = xmlDocument.CreateElement( ElementNam e)
Dim enumAttr As IDictionaryEnumerator
If Not htAttr Is Nothing And htAttr.Count <> 0 Then
enumAttr = htAttr.GetEnumerator
While enumAttr.MoveNext
objElement.SetAttribute(en umAttr.Key .ToString( ), enumAttr.Value.ToString())
End While
End If
objElement.AppendChild(xml Document.C reateTextN ode(elemen tString))
Return objElement
End Function
Private Sub createXML_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ensalada_btn.Click
Try
'Initialize a XmlTextWrite Object
Dim xmlDoc As XmlDocument
'Instantiate an xmlDocument
xmlDoc = New XmlDocument
'Create a XmlDeclaration & append Declaration
Dim xmlDec As XmlDeclaration = xmlDoc.CreateXmlDeclaratio
xmlDoc.AppendChild(xmlDec)
'Create a root Element
Dim rootElement As XmlElement = xmlDoc.CreateElement("Tran
'Create First Level
Dim elementLevelOne As XmlElement = xmlDoc.CreateElement("Orde
elementLevelOne.SetAttribu
Dim hsAttr As New Hashtable
hsAttr.Add("badge", "1235")
hsAttr.Add("date", "2004/08/03")
elementLevelOne.AppendChil
rootElement.AppendChild(el
xmlDoc.AppendChild(rootEle
xmlDoc.Save("c:/test1.xml"
Catch ex As XmlException
MsgBox(ex.Message)
End Try
End Sub
Function myElement(ByVal xmlDocument As XmlDocument, ByVal ElementName As String, ByVal elementString As String, ByVal htAttr As Hashtable) As XmlElement
'Add Element & Attributes to a XML Element
Dim objElement As XmlElement = xmlDocument.CreateElement(
Dim enumAttr As IDictionaryEnumerator
If Not htAttr Is Nothing And htAttr.Count <> 0 Then
enumAttr = htAttr.GetEnumerator
While enumAttr.MoveNext
objElement.SetAttribute(en
End While
End If
objElement.AppendChild(xml
Return objElement
End Function
ASKER
Add more nodes to the same root for example
<root>
<node>Example1 </node>
<node>Example2 </node>
</root>
<root>
<node>Example1 </node>
<node>Example2 </node>
<node>Example3</node>
</root>
Something like insert a new record in the DB
<root>
<node>Example1 </node>
<node>Example2 </node>
</root>
<root>
<node>Example1 </node>
<node>Example2 </node>
<node>Example3</node>
</root>
Something like insert a new record in the DB
Are you using XML as a database?
Bob
Bob
ASKER
Yes I'm but now I have another question for you guys do you know how to delete a specific childNode on the XML database
for example
<root>
<node key=1>Example1 </node>
<node key=2>Example2 </node>
<node key=3>Example3</node>
</root>
how can I delete the key 2 from the roop parent
(I'm using VB.NET and XML db)
for example
<root>
<node key=1>Example1 </node>
<node key=2>Example2 </node>
<node key=3>Example3</node>
</root>
how can I delete the key 2 from the roop parent
(I'm using VB.NET and XML db)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Bob