catching errors with XPathExpression

Discussion in 'ASP .Net' started by darrel, Sep 28, 2005.

  1. darrel

    darrel Guest

    I have a function that I pass some variables to, that then goes into an XML
    file and returns some other values:

    dim expr as System.Xml.XPath.XPathExpression = xpn.Compile("//" &
    variableToReturn & "[../pageID = '" & pageID & "']")
    dim ni as System.Xml.XPath.XPathNodeIterator = xpn.Select(expr)

    ni.MoveNext()

    if ni.Current.Value <> "" then
    valueToReturn = ni.Current.Value
    else
    valueToReturn = "null"
    end if

    return valueToReturn

    So, I'm passing one string 'variableToReturn' which chooses the node to
    grab, and 'pageID' which tell it from which parent node to grab tge
    variableToReturn.

    This works just fine when I pass a pageID that exists in the XML file:

    //contentID[../3]

    That will return the value of 'contentID' from the node that also has a
    pageID = 3.

    The problem is when a pageID value is passed that doesn't exist in the XML
    file. Instead of returning nothing, it grabs every single value of every
    single node and appends it into this gigantic string. (example: 702nd
    HomeHomeFalsenoneFalse087DepartmentsDivisionsFalsenoneTrue1 )

    It appears that my expression isn't maybe doing a proper error check to
    first see if the node even exists and isntead just grabs everything. Anyone
    see a fix for this? Is it a more sophisicated expression?

    -Darrel
     
    darrel, Sep 28, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mikael Engdahl

    Catching ASP.NET errors

    Mikael Engdahl, Aug 15, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,379
    S. Justin Gengo
    Aug 15, 2003
  2. TonyG

    Catching Framework Errors

    TonyG, Aug 23, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    323
    MS News \(MS ILM\)
    Aug 26, 2003
  3. Mark Goldin

    Errors, errors, errors

    Mark Goldin, Jan 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    964
    Mark Goldin
    Jan 17, 2004
  4. Martin Honnen
    Replies:
    0
    Views:
    386
    Martin Honnen
    Jul 18, 2008
  5. yawnmoth
    Replies:
    97
    Views:
    4,726
    Bent C Dalager
    Feb 27, 2009
Loading...

Share This Page