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. 7 1535
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
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" <no****@nowhere.com> wrote in message
news:NU*******************@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.
Mark Schupp:
Your function worked for me. Thank you!
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...
"joe" <no****@nowhere.com> wrote in message
news:57********************@news20.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.
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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??
...
|
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...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |