Professional Web Applications Themes

Please clarify how null nodeset result processes? - ASP.NET General

Hi, I continue to have trouble with this. Using the following xml sample: <Station name="Station1" line_stop="yes"/> OR when NO line_stop attribute exists. In asp.net page, I use xpath to determine IF the line_stop attribute exists (or am TRYING to!) Dim xDoc as XmlDoent Dim xNode As XmlElement = xDoc.SelectSingleNode("//Station[name='Station1'][line_stop='yes']") If Not xNode.Value Is Nothing Then If xNode.Value = "yes" Then do this... End If End If If there is no line_stop attribute, I get an error for "Object reference not set to an instance of an object" at the If Not xNode.Value line...obviously returning no node. Please tell me where ...

  1. #1

    Default Please clarify how null nodeset result processes?

    Hi, I continue to have trouble with this. Using the following xml
    sample:

    <Station name="Station1" line_stop="yes"/>

    OR when NO line_stop attribute exists.

    In asp.net page, I use xpath to determine IF the line_stop attribute
    exists (or am TRYING to!)

    Dim xDoc as XmlDoent
    Dim xNode As XmlElement =
    xDoc.SelectSingleNode("//Station[name='Station1'][line_stop='yes']")

    If Not xNode.Value Is Nothing Then
    If xNode.Value = "yes" Then
    do this...
    End If
    End If

    If there is no line_stop attribute, I get an error for "Object reference
    not set to an instance of an object" at the If Not xNode.Value
    line...obviously returning no node.

    Please tell me where I'm going wrong.

    Thanks,
    Kathy

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Guest

  2. #2

    Default Re: Please clarify how null nodeset result processes?

    Kathy, you might get better responses in the .framework group, since this
    doesn't seem to be specific to ASP.NET.

    --
    John Saunders
    Internet Engineer
    com


    "Kathy Burke" <com> wrote in message
    news:%phx.gbl... 


    John Guest

  3. #3

    Default Re: Please clarify how null nodeset result processes?

    check if the xNode is nothing first


    "Kathy Burke" <com> wrote in message
    news:%phx.gbl... 


    MS Guest

  4. #4

    Default Re: Please clarify how null nodeset result processes?

    Doesn't "If Not xNode.Value Is Nothing Then" check that xNode is
    nothing?

    Thanks.

    Kathy

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Guest

  5. #5

    Default Re: Please clarify how null nodeset result processes?

    "Kathy Burke" <com> wrote in message
    news:phx.gbl... 

    No. That checks to see if xNode.Value is Nothing. If xNode is Nothing, the
    above "If" statement will throw a NullReferenceException.

    To see if xNode is Nothing try:

    If Not xNode is Nothing Then

    --
    John Saunders
    Internet Engineer
    com



    John Guest

  6. #6

    Default Re: Please clarify how null nodeset result processes?

    Hi again,

    I've tried adding:

    If Not n16 Is Nothing Then
    If n16.Value = "yes" Then
    Dim strNext As String = "yes"
    End If
    End If

    but still get a NullReferenceException on the first line of the above
    snippet. In this particular case, I SHOULD get "nothing" as a result
    since the attribute 'line_stop' doesn't exist for the element
    selected...but the code should then continue, yes?

    Any suggestions for how I can proceed?

    Kathy

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Kathy Guest

Similar Threads

  1. Replies: 3
    Last Post: March 21st, 10:22 AM
  2. .net client + Axis 1.1 server + wrapped param: null result
    By Zihong Lu in forum ASP.NET Web Services
    Replies: 13
    Last Post: June 23rd, 09:53 PM
  3. WaitForMultipleObjects: let's clarify
    By Markus in forum UNIX Programming
    Replies: 13
    Last Post: September 17th, 06:22 AM
  4. Replies: 0
    Last Post: July 25th, 04:59 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139