given a snippet from an XML message
...
<DATA name="John" value="23" />
<DATA name="Betty" value="71" />
<DATA name="Craig" value="" />
<DATA name="Lisa" value="42" />
...
I load this into the Xml Dom in .Net (VB), and query each node for the
'name' and 'value' attributes.
When I get to an instance where the attribute is empty (as in the case where
name=Craig),
Attributes("value").Value.ToString
returns null?
Surely this should return "" on the basis that the attribute does exist?!
I then pass this value into the Parameters.Add method of an OdbcCommand
object, and sending in null throws an exception because no value is
supplied, so each time i pass in a parameter i need to check for null from
the attribute.
Dan.
Merry Christmas!
Oleg Tkachenko - 24 Dec 2003 12:10 GMT
> given a snippet from an XML message
>
[quoted text clipped - 14 lines]
>
> Surely this should return "" on the basis that the attribute does exist?!
Well, I cannot reproduce the problem. It is empty string, not null.

Signature
Oleg Tkachenko
XML Insider
http://www.tkachenko.com/blog
Chris Lovett - 29 Dec 2003 17:44 GMT
Are you sure you loaded the element? The following program prints
"Empty:Craig". Note that I had to wrap your XML in a root element so that
it becomes a well formed XML document.
Imports System
Imports System.Xml
Module Module1
Sub Main()
Dim doc As New XmlDocument()
Dim e As XmlElement
Dim v As String
doc.LoadXml("<test>" + _
"<DATA name='John' value='23' />" + _
"<DATA name='Betty' value='71' />" + _
"<DATA name='Craig' value='' />" + _
"<DATA name='Lisa' value='42' />" + _
"</test>")
For Each e In doc.SelectNodes("/test/DATA")
With (e)
v = .Attributes("value").Value
If (v = String.Empty) Then
Console.WriteLine("Empty:" + .Attributes("name").Value)
End If
End With
Next
Return
End Sub
End Module
> given a snippet from an XML message
>
[quoted text clipped - 23 lines]
>
> Merry Christmas!