473,770 Members | 7,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLDOM / Conditional Check for Object fails

joe
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.selec tSingleNode("//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.leng ht = 0 Then
3. If oItemPrice = empty or oItemPrice = "" or isnull(oItemPri ce) 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.


Jul 22 '05 #1
7 1556
joe
With JScript one can just go:

oItemPrice = xmlDoc.selectSi ngleNode("//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.leng ht = 0 Then
3. If oItemPrice = empty or oItemPrice = "" or isnull(oItemPri ce) Then
4. If not (oItemPrice) Then

Jul 22 '05 #2
try this:

If Not IsDomTextNode( oItemPrice) Then
....

'check if selectSingleNod e 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" <no****@nowhere .com> wrote in message
news:NU******** ***********@new s20.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.selec tSingleNode("//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.leng ht = 0 Then
3. If oItemPrice = empty or oItemPrice = "" or isnull(oItemPri ce) 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.



Jul 22 '05 #3
joe
Mark Schupp:

Your function worked for me. Thank you!
Jul 22 '05 #4
joe
Lately I've been surfing the MS knowledge pages to find XML related stuff,
and I've noticed that (of the two primary scripting languages used with ASP)
Jscript has way much more prominence that VBscript in the examples given.
Acutally, most of what I found was Jscript, C++ and Visual Basic.

Is MS pushing JScript as a preferred scripting language for their present
and future technologies? Not that I care, I like JScript. Just trying to see
where things are heading...
Jul 22 '05 #5
"joe" <no****@nowhere .com> wrote in message
news:57******** ************@ne ws20.bellglobal .com...
Lately I've been surfing the MS knowledge pages to find XML related stuff,
and I've noticed that (of the two primary scripting languages used with ASP) Jscript has way much more prominence that VBscript in the examples given.
Acutally, most of what I found was Jscript, C++ and Visual Basic.

Is MS pushing JScript as a preferred scripting language for their present
and future technologies? Not that I care, I like JScript. Just trying to see where things are heading...

JScript (JavaScript, ECMAScript) are often used client-side as they are
cross-browser compatible; whereas, VBScript requires an IE browser.
Jul 22 '05 #6
joe wrote:
Lately I've been surfing the MS knowledge pages to find XML related
stuff, and I've noticed that (of the two primary scripting languages
used with ASP) Jscript has way much more prominence that VBscript in
the examples given. Acutally, most of what I found was Jscript, C++
and Visual Basic.

Is MS pushing JScript as a preferred scripting language for their
present and future technologies? Not that I care, I like JScript.
Just trying to see where things are heading...


IE is the only browser that will run vbscript in client-side code ... If you
want cross-browser capabilities, you need to use javascript/jscript when
writing client-side code.

Bob Barrows

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #7
Sorry about coming late to this party, but I think there's a much simpler
solution ...

Set oItemPrice = objXMLDoc.selec tSingleNode("//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.
Jul 22 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1989
by: jfizer | last post by:
I have a web app that uses a form with its fields populated from XML using Microsoft.XMLDOM. The problem is that Microsoft.XMLDOM functions seem to run on their own thread, so I dont know when the fields are done populating. Can anyone think of a way for me to check when the following function finishes? function importXML(xmlQuery,xmlSrc,xmlTarget) {
3
4279
by: Robert Zurer | last post by:
Hello all, I want to load an in-memory XmlDocument from the server to the client and create an XMLDOM object using javascript. I can do it from a url by calling this Javascript from the client. var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load("url of the persisted file");
28
3464
by: Benjamin Niemann | last post by:
Hello, I've been just investigating IE conditional comments - hiding things from non-IE/Win browsers is easy, but I wanted to know, if it's possible to hide code from IE/Win browsers. I found <!> in the original MSDN documentation, but this is (although it is working) unfortunately non-validating gibberish. So I fooled around trying to find a way to make it valid. And voila: <!--><!><!-->
1
1920
by: Dave Romig | last post by:
Can anyone provide guidance for saving and restoring an XMLDOM object as a binary blob? In a VB application, I need to repeatedly save and restore a large, dynamic XML document. Currently, the CPU overhead of serialization and de-serialization is KILLING performance. I have done some tests and if I could persist the DOM as a binary blob, I think the performance issues would be resolved. A pair of orthogonal functions that translate...
0
958
by: Robert Zurer | last post by:
Hello all, I want to load an in-memory XmlDocument from the server to the client and create an XMLDOM object using javascript. I can do it from a url by calling this Javascript from the client. var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async = "false"; xmlDoc.load(url);
9
26850
by: B | last post by:
I have an XML string <?xml version="1.0" encoding="UTF-8"?> <SSOUser><Status>FAIL</Status><Message>Unable to find session id of 1137018716939</Message></SSOUser> That I am trying to retrieve the values between the tags for. I want to get the value from <Status>FAIL</Status>
4
1925
by: a | last post by:
I'm having trouble testing a custom object. I've tried many different approaches. One is shown below. The XML below shows the state of the object and I'm trying to test for that state, ie there are NO classes in the Classes collection (Classes) of the custom object. The conditional expression returns the error shown below it... =======================================================XML returned by
5
1827
by: Dikkuuhh | last post by:
I must get a lot of information out of my database into a XMLDOM. The database part is done, all the information is in SQLDataReaders, but how can i convert all that information into a XMLDOM?? I must get it nice so i can load the information later.. Greetz Koen
8
8508
by: Typehigh | last post by:
I have many text fields with conditional formatting applied, specifically when the condition is "Field Has Focus". Without any events associated with the fields the conditional formatting works perfectly. However, I have code that runs under the ON CLICK event. The code changes the focus to other controls, which means the conditional formatting is no longer displayed. This part makes sense to me. Here's what doesn't make sense. The last...
0
10230
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10058
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10004
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9870
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5450
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.