Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

XMLDOM / Conditional Check for Object fails
I am having problems checking for the value of an XMLDOM object .

Lets say my XMLDOM object was successfully created as objXMLDoc, and that
has several nodes on it. In the case of a VBScript loop like below:

'-------------------
For x = 1 To 10

Set oItemPrice = objXMLDoc.selectSingleNode("//Item[x]/Price")

'--- conditional stuff that fails here

Next
'-------------------

some of the Items don't have a price, therefore the object oItemPrice will
fail at some point. So I want to check for this failure, but everything I do
gives me errors.
Examples:

1.  If not oItemPrice Then
2.  If oItemPrice.lenght = 0 Then
3.  If oItemPrice = empty or oItemPrice = "" or isnull(oItemPrice) Then
4.  If not (oItemPrice) Then

I really don't know what to do. Most errors are like:
" Object doesn't support this property or method"

Any help is appreciated.









Report this thread to moderator Post Follow-up to this message
Old Post
joe
06-01-05 01:55 AM


Re: XMLDOM / Conditional Check for Object fails
With JScript one can just go:

oItemPrice   =  xmlDoc.selectSingleNode("//Item["+x+"]/Price");

if (oItemPrice)  { ...do stuff }
else {...do other stuff}

but because my XMLDOM code must go inside VBScrip pages, I have to figure
the other one out.
I tried to mix both languages up and ended up with even more problems.


> some of the Items don't have a price, therefore the object oItemPrice will
> fail at some point. So I want to check for this failure, but everything I
do
> gives me errors.
> Examples:
>
> 1.  If not oItemPrice Then
> 2.  If oItemPrice.lenght = 0 Then
> 3.  If oItemPrice = empty or oItemPrice = "" or isnull(oItemPrice) Then
> 4.  If not (oItemPrice) Then



Report this thread to moderator Post Follow-up to this message
Old Post
joe
06-01-05 01:55 AM


Re: XMLDOM / Conditional Check for Object fails
try this:

If Not IsDomTextNode( oItemPrice) Then
...

'check if selectSingleNode returned a valid text node
Function IsDomTextNode( ByRef objNode )

Dim strTmp

On Error Resume Next
strTmp = objNode.text

If Err.Number = 0 Then
IsDomTextNode = True
Else
IsDomTextNode = False
End If

End Function

You should also be able to use the nodeType property of the node to see if
it is the type you expect. I can't remember why I used to above approach.

--
--Mark Schupp


"joe" <nobody@nowhere.com> wrote in message
news:NU1ne.9698$_r1.479079@news20.bellglobal.com...
>I am having problems checking for the value of an XMLDOM object .
>
> Lets say my XMLDOM object was successfully created as objXMLDoc, and that
> has several nodes on it. In the case of a VBScript loop like below:
>
> '-------------------
> For x = 1 To 10
>
>  Set oItemPrice = objXMLDoc.selectSingleNode("//Item[x]/Price")
>
>  '--- conditional stuff that fails here
>
> Next
> '-------------------
>
> some of the Items don't have a price, therefore the object oItemPrice will
> fail at some point. So I want to check for this failure, but everything I
> do
> gives me errors.
> Examples:
>
> 1.  If not oItemPrice Then
> 2.  If oItemPrice.lenght = 0 Then
> 3.  If oItemPrice = empty or oItemPrice = "" or isnull(oItemPrice) Then
> 4.  If not (oItemPrice) Then
>
> I really don't know what to do. Most errors are like:
> " Object doesn't support this property or method"
>
> Any help is appreciated.
>
>
>
>
>
>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Mark Schupp
06-01-05 01:55 AM


Re: XMLDOM / Conditional Check for Object fails
Mark Schupp:

Your function worked for me. Thank you!



Report this thread to moderator Post Follow-up to this message
Old Post
joe
06-01-05 01:55 AM


RE: XMLDOM / Conditional Check for Object fails
Sorry about coming late to this party, but I think there's a much simpler
solution ...

Set oItemPrice = objXMLDoc.selectSingleNode("//Item[x]/Price")
If Not oItemPrice Is Nothing Then
' You can use oItemPrice in here.
End If

Yes, VB and VBScript are a little odd in this area, because they prefer to
use the default property of an object when assigning and comparing.  This is
why there is the special "Set" statement and the above "Is" operator, which
act upon the object pointer itself, not its default property.

Report this thread to moderator Post Follow-up to this message
Old Post
David Patow
06-09-05 08:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

ASP archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:38 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.