none
replace innerxml RRS feed

  • Question

  • I have xml files that i want to replace the innerxml of one of its tags , the thing is that these xmls cintain empty tags :

    say :

    <id> john smith </id

    <decree/>  ---> if decree is empty what i need is to insert the value = 0 , so i will have

    <decree<0<decree/> instead of <decree/>

    i am reading the values into textboxes , all are working fine but , as for the decree , i have tried many ways like :

    if txtdecree.text = " " then

    txtdecree.text = Cstr(0)

    or if txtdecree.text = string.empty then

    txtdecree.text = Cstr(0)

    any suggestion on that  ?


    Georges Naffah

    Saturday, June 2, 2012 4:55 PM

Answers

  • Hi Georges,

    Welcome to the MSDN Forum.

    Based on your description, it makes me a little confused: your text description said you want to replace the XML empty node, but your code seems to tell me you want to change the text value of a textbox control. Which is what you really want to do?

    If you want to change the xml node value in an xml file, please take a look at this sample code:

        Private Sub ChangeXmlNodeValue()
            Dim xmlfile As XmlDocument = New XmlDocument()
            xmlfile.Load("d:\file\ChangeNodeValue.xml")
    
            Dim emptyNode As XmlNode = xmlfile.FirstChild.FirstChild
            Console.WriteLine(emptyNode.InnerXml)
    
            emptyNode.InnerXml = "NotEmptyValue"
    
    
            xmlfile.Save("d:\file\ChangeNodeValue.xml")
            xmlfile.Load("d:\file\ChangeNodeValue.xml")
            emptyNode = xmlfile.FirstChild.FirstChild
            Console.WriteLine(emptyNode.InnerXml)
        End Sub

    The test xml file is:

    <root>
      <EmptyNode />
    </root>

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 4, 2012 5:46 AM
    Moderator