SelectSingeNode("xpath")...how to test if null?

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default SelectSingeNode("xpath")...how to test if null?

    Hi, I'm using

    Dim xDoc as XmlDocument
    Dim xElem As xmlElement = xDoc("xpath")

    I then assign a variable to a value from the result node:
    Dim r As String = xElem.Attributes.GetNamedItem("name").Value

    This works fine unless there is no node returned, then I get an "object
    reference not set" error.

    How do you test for an empty node return?

    Thanks again for all the help.

    Kathy

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

  2. Similar Questions and Discussions

    1. #39593 [NEW]: XPath NodeList: "Couldn't fetch DOMElement: Node no longer exists"
      From: dave dot lane at gmx dot net Operating system: Linux PHP version: 5.2.0 PHP Bug Type: DOM XML related Bug description:...
    2. #39593 [Opn]: XPath NodeList: "Couldn't fetch DOMElement: Node no longer exists"
      ID: 39593 User updated by: dave dot lane at gmx dot net Reported By: dave dot lane at gmx dot net Status: Open Bug...
    3. cfqueryparam ignores null="yes" when list="yes"
      I get an unexpected result when using cfqueryparam with list="yes" and null="yes" using CF 7.0.1 and MSSQL 2000. When i run this code: <cfset...
    4. "Devel::DProf" on a PERL script uses "Test::More"
      Dear all, I encountered a problem while run profiling on a script which uses "Test::More". May I ask whether anybody have some idea or wrap...
    5. "null null" error on line -1
      Hi, A different, new, ocasional error this time. Since we are using CFMX7, occasionally we get this error: " Application Exception Monitor...
  3. #2

    Default Re: SelectSingeNode("xpath")...how to test if null?

    Kathy,

    Try:

    Dim r As String
    If Not xElem.Attributes.GetNamedItem("name") Is Nothing Then
    Dim r As String = xElem.Attributes.GetNamedItem("name").Value
    End If
    --
    S. Justin Gengo, MCP
    Web Developer

    Free code library at:
    [url]www.aboutfortunate.com[/url]

    "Out of chaos comes order."
    Nietzche
    "Kathy Burke" <kathyburke40@attbi.com> wrote in message
    news:eYud88UUDHA.2220@TK2MSFTNGP11.phx.gbl...
    > Hi, I'm using
    >
    > Dim xDoc as XmlDocument
    > Dim xElem As xmlElement = xDoc("xpath")
    >
    > I then assign a variable to a value from the result node:
    > Dim r As String = xElem.Attributes.GetNamedItem("name").Value
    >
    > This works fine unless there is no node returned, then I get an "object
    > reference not set" error.
    >
    > How do you test for an empty node return?
    >
    > Thanks again for all the help.
    >
    > Kathy
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    S. Justin Gengo Guest

  4. #3

    Default Re: SelectSingeNode("xpath")...how to test if null?

    Thanks, Justin. That did the trick of course. I wasn't using the
    "nothing"...

    thanks.

    Kathy

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

Posting Permissions

  • You may not post new threads
  • You may 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