|
-
Jun 27th, 2008, 10:45 AM
#1
Thread Starter
Hyperactive Member
[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
-
Jun 27th, 2008, 10:49 AM
#2
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.
-
Jun 27th, 2008, 11:01 AM
#3
Thread Starter
Hyperactive Member
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.
-
Jun 27th, 2008, 11:21 AM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|