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

    • Changed type Mike Feng Monday, June 4, 2012 5:47 AM This is a question.
    Saturday, June 2, 2012 4:55 PM


  • 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()
            Dim emptyNode As XmlNode = xmlfile.FirstChild.FirstChild
            emptyNode.InnerXml = "NotEmptyValue"
            emptyNode = xmlfile.FirstChild.FirstChild
        End Sub

    The test xml file is:

      <EmptyNode />

    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.

    • Proposed as answer by RohitArora Monday, June 4, 2012 7:26 AM
    • Marked as answer by Mike Feng Monday, June 18, 2012 1:22 PM
    Monday, June 4, 2012 5:46 AM