Hopefully an easy question:
Using vb.net I have opened an xml file (which is encrypted) retreived the file information as a string, carry out some editing of the xml data. I now want to produce a string with the edited information so that I can pass it to a function which will encrypt and save the xml file.
I can do all of the above except for the regenerating the edited xml data into a string after it has been edited.
This is my code:
Dim xmlDoc As New XmlDocument
Dim userNodes As XmlNodeList
Dim userDetailNodes As XmlNodeList
Dim userNode As XmlNode
xmlDoc.LoadXml( xmlString)
userNodes = xmlDoc.GetEleme ntsByTagName("U ser")
For Each userNode In userNodes
userDetailNodes = userNode.ChildN odes
userDetailNodes (userNameLoc).I nnerText = userName
next
*********
All of the above works fine (Its only an extract to give you the basic idea)
Now I would like to pass the xml string to my function:
saveFile(xmlStr ing)
however xmlString does not contain the updated information.
I have got around this problem by saving the xmldoc as a temp file, loading the temp file into a string and then saving it back into the encrypted file (code below) but there must be a better way of doing this???? All help appreciated!
xmlDoc.Save("C: \temp.xml")
Dim fs As New FileStream("C:\ temp.xml", FileMode.Open, FileAccess.Read )
Dim sr As New StreamReader(fs )
Dim tempText As String
tempText = sr.ReadToEnd()
fs.Close()
My.Computer.Fil eSystem.DeleteF ile("C:\temp.xm l")
saveUserDetails (tempText)
Using vb.net I have opened an xml file (which is encrypted) retreived the file information as a string, carry out some editing of the xml data. I now want to produce a string with the edited information so that I can pass it to a function which will encrypt and save the xml file.
I can do all of the above except for the regenerating the edited xml data into a string after it has been edited.
This is my code:
Dim xmlDoc As New XmlDocument
Dim userNodes As XmlNodeList
Dim userDetailNodes As XmlNodeList
Dim userNode As XmlNode
xmlDoc.LoadXml( xmlString)
userNodes = xmlDoc.GetEleme ntsByTagName("U ser")
For Each userNode In userNodes
userDetailNodes = userNode.ChildN odes
userDetailNodes (userNameLoc).I nnerText = userName
next
*********
All of the above works fine (Its only an extract to give you the basic idea)
Now I would like to pass the xml string to my function:
saveFile(xmlStr ing)
however xmlString does not contain the updated information.
I have got around this problem by saving the xmldoc as a temp file, loading the temp file into a string and then saving it back into the encrypted file (code below) but there must be a better way of doing this???? All help appreciated!
xmlDoc.Save("C: \temp.xml")
Dim fs As New FileStream("C:\ temp.xml", FileMode.Open, FileAccess.Read )
Dim sr As New StreamReader(fs )
Dim tempText As String
tempText = sr.ReadToEnd()
fs.Close()
My.Computer.Fil eSystem.DeleteF ile("C:\temp.xm l")
saveUserDetails (tempText)