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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML DOM searching/filters 1

Status
Not open for further replies.

fredmartinmaine

IS-IT--Management
Mar 23, 2015
79
US
<Properties>
<Property>
<LocationNumber>023</LocationNumber>
<BuildingNumber>001</BuildingNumber>
<BldgCost>234500</BldgCost>
<BldgSqFt>1200</BldgSqFt>

There are one or more <Property> nodes.
I'd like to work with a <Property> but only want the one with a specific location number in it. Once I find that <Property> I'll be extracting the text from the child nodes, such as <BldgCost>.

I'm having trouble finding syntax that works. This does not:

Set node = objDoc.SelectSingleNode("Properties/Property[LocationNumber/text()='023']")
MsgBox(node.text)

Result is 'Object required: node' from the MsgBox line. I assume that means there's no error in the Select line, it's just not finding anything.

As well, when I get this working, that ='023' will need to be a variable, like:

Set node = objDoc.SelectSingleNode("Properties/Property[LocationNumber/text()=LocNum]")

Mr. Google isn't helping me find an example that works with VBScript.
 
Ok hold everything - the trouble is the data. Turns out, and I was stepping in this, there can be multiple buildings in one location and so, more than one LocationNumber = '023' is plausible.

Set Nodes = objDoc.GetElementsByTagName("Properties/Property[LocationNumber/text()='023']")
For Each Node in Nodes
MsgBox(node.text)
Next

So that works. Now I'm having trouble getting a variable to work in place of the constant. This fails:

GetElementsByTagName("Properties/Property[LocationNumber/text()=LocNum]")

Anybody have a sample of filtering with a variable?

Fred
 
Try something like this:
Code:
GetElementsByTagName("Properties/Property[LocationNumber/text()=[highlight #FCE94F]" & LocNum & "[/highlight]]")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top