Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking if a node is empty/blank/null 1

Status
Not open for further replies.

Jetter88

Programmer
Nov 14, 2003
35
CA
hi...
I'm trying to figure out how to deteremine if a node is empty/blank/null before setting the value otherwise i get an "object required" error.
I'm have to use ASP 3.0 classic to retrieve the xml.
If the "Action" node is empty/blank/null, i get an error.

Thanks in advance!

code used:
set docReceived = CreateObject("MSXML.DOMDocument")
docReceived.async = False
docReceived.load myRequest.responseXML
'Parse XML
Set listItem = docReceived.selectnodes("Response")
for each node in listItem
Action = ""
Action = node.selectsinglenode("DataArea/Action").firstchild.nodevalue
next

 
[0] The problem is that you cannot be certain selectsinglenode returns anything, and that even it returns a xmlnode, calling upon its firstchild could be "nothing" for Action if it is empty or just containing non-significant whitespaces.

[1] If you insist on using firstchild, you can do this.
[tt]
[red]'[/red]Action = node.selectsinglenode("DataArea/Action").firstchild.nodevalue
set oAction=node.selectsinglenode("DataArea/Action")
if not oAction is nothing then
if not oAction.firstchild is nothing then
Action=oAction.firstchild.nodevalue
end if
end if
[/tt]
[1.1] If the Action element is expected to be of simple content, you can simply it about to make it more efficient.
[tt]
[red]'[/red]Action = node.selectsinglenode("DataArea/Action").firstchild.nodevalue
set oAction=node.selectsinglenode("DataArea/Action")
if not oAction is nothing then
Action=oAction.text
end if
[/tt]
which would be an empty string one way or another if it is empty or containing only non-significant whitespaces as the parser being used is not schema-aware and its text content won't be null.
 
I changed all the code to option [1.1] and it works!
Thank you again.
very much appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top