Jscript variable in XPath expression

J

j_kowalska

Hi, I'm new to XPath

Could anybody tell me how to use Jscript variable in XPath expression?

In the folowwing code I get an error ' object required':
....
var selectedCustomer =
XDocument.DOM.selectSingleNode("/my:mojePola/my:Customer").text

var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
= selectedCustomer]")
....
when I replace selectedCustomer (in the second line) with a string,
e.g.
....
var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
='somestring' ]")
....
everything is OK.

Any hints appreciated,
jpk_2005
 
S

S.Y.M. Wong-A-Ton

Your problem might be in another area than where you think it is, but to use
the variable in the expression try this:

var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
= '" + selectedCustomer + "']")

If this doesn't solve the error, your problem is probably in one of the
XPAth expressions you have used. The XML nodes are not being found, so you'll
need to debug your XPath expression to find the correct one to the XML nodes
you want to find.
 
J

j_kowalska

Thanks a lot, it solved my problem:)




S.Y.M. Wong-A-Ton napisal(a):
Your problem might be in another area than where you think it is, but to use
the variable in the expression try this:

var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
= '" + selectedCustomer + "']")

If this doesn't solve the error, your problem is probably in one of the
XPAth expressions you have used. The XML nodes are not being found, so you'll
need to debug your XPath expression to find the correct one to the XML nodes
you want to find.
---
S.Y.M. Wong-A-Ton


Hi, I'm new to XPath

Could anybody tell me how to use Jscript variable in XPath expression?

In the folowwing code I get an error ' object required':
....
var selectedCustomer =
XDocument.DOM.selectSingleNode("/my:mojePola/my:Customer").text

var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
= selectedCustomer]")
....
when I replace selectedCustomer (in the second line) with a string,
e.g.
....
var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
='somestring' ]")
....
everything is OK.

Any hints appreciated,
jpk_2005
 
S

S.Y.M. Wong-A-Ton

You're welcome. Glad it solved the problem.
---
S.Y.M. Wong-A-Ton


Thanks a lot, it solved my problem:)




S.Y.M. Wong-A-Ton napisal(a):
Your problem might be in another area than where you think it is, but to use
the variable in the expression try this:

var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
= '" + selectedCustomer + "']")

If this doesn't solve the error, your problem is probably in one of the
XPAth expressions you have used. The XML nodes are not being found, so you'll
need to debug your XPath expression to find the correct one to the XML nodes
you want to find.
---
S.Y.M. Wong-A-Ton


Hi, I'm new to XPath

Could anybody tell me how to use Jscript variable in XPath expression?

In the folowwing code I get an error ' object required':
....
var selectedCustomer =
XDocument.DOM.selectSingleNode("/my:mojePola/my:Customer").text

var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
= selectedCustomer]")
....
when I replace selectedCustomer (in the second line) with a string,
e.g.
....
var selectedNode =
doc.selectSingleNode("/dfs:myFields/dfs:dataFields/dfs:Kontakty[@Nazwisko
='somestring' ]")
....
everything is OK.

Any hints appreciated,
jpk_2005
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top