Showing posts with label read inner text. Show all posts
Showing posts with label read inner text. Show all posts

Friday, September 2, 2011

Printing and updating the inner text of a xml node in vb.net

Hi guys this is the code for printing and updating the inner text of node in a xml file through vb.net code which i used update my xml file name as content.xml
****************************
content.xml
*************************
<?xml version="1.0" encoding="utf-8"?>
<main>
  <node1 id="1">my old text</node1>
</main>


******************************



This function is to print inner text of a xml node

Public Function shw()

Dim strxmlpath As String = Server.MapPath("content.xml")
            Dim doc As New XmlDocument
            doc.Load(strxmlpath)
            Dim elem As XmlNode = doc.DocumentElement.FirstChild
Response.Write(elem.InnerText)
             doc.Save(strxmlpath)

End Function


This function is to update inner text of a xml file

Public Function updt()
 Dim strxmlpath As String = Server.MapPath("content.xml")
            Dim doc As New XmlDocument
            doc.Load(strxmlpath)
            Dim node As XmlNode = doc.DocumentElement.FirstChild
            node.InnerText = " enter your new text"


            doc.Save(strxmlpath)
End Function