Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / December 2003

Tip: Looking for answers? Try searching our database.

Xml Dom .net bug???

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Daniel Bass - 24 Dec 2003 11:40 GMT
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!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.