Results 1 to 4 of 4

Thread: [2005] How to update XML Innertext on empty node?

  1. #1

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    [2005] How to update XML Innertext on empty node?

    I have nodes that can be empty in my XML Document.

    Example:

    <mydoc>
    <attachment></attachment>
    <mydoc>

    The attachment node may or may not be empty depending upon if there is an attachment.

    How do I update the innertext, as of now the code below throws an null exception:

    Code:
        Public Sub SetXMLArgsValue(ByVal ConfigName As String, ByVal NewValue As Integer)
            Dim Node As String
            Dim xmlDoc As New XmlDocument
            Dim xmlNode As XmlNode
    
            Try
                'load document
                xmlDoc.Load(Application.StartupPath & "\Config.xml")
                'set node base
                Node = "/mydoc/" & ConfigName
                'get node
                xmlNode = xmlDoc.SelectSingleNode(Node)
                'get node value
                xmlNode.InnerText = NewValue'<----exception thrown here
                'save 
                xmlDoc.Save(Application.StartupPath & "\Config.xml")
            Catch ex As Exception
                Throw New Exception(ex.Message & " - SetXMLConfigValue")
            Finally
                xmlNode = Nothing
                xmlDoc = Nothing
            End Try
        End Sub

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] How to update XML Innertext on empty node?

    put a break point on this line:

    xmlNode.InnerText = NewValue'<----exception thrown here

    then run your code. When the code breaks on that line, add a watch to xmlNode, and make sure that is not is what is null.

    There should not be a problem assigning innerttext to a node so long as the node is a valid node.

  3. #3

    Thread Starter
    Hyperactive Member maikeru-sama's Avatar
    Join Date
    May 2008
    Posts
    339

    Re: [2005] How to update XML Innertext on empty node?

    kleinma, false alarm. Seems when accessing elements this way, it is "Case Sensitive". I was passing in "GopClosed" and the element in XML is "GOPClosed".

    Thanks for the help.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] How to update XML Innertext on empty node?

    Just for future reference. XML is and always has been case sensitive. Always. So "when accessing elements this way..." should actually read "when accessing elements in any way..."

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width