String interpreted correct?

P

Petterson Mikael

How can I add a java String variable to an XPath expression?

Example:

String parent = "John";
String query =
"//Foundation.Core.Class[Foundation.Core.ModelElement.name='"+parent+"']/Foundation.Core.Gene
ralizableElement.specialization"

But it gives:


//Foundation.Core.Class[Foundation.Core.ModelElement.name='John']/Foundation.Core.Gene
ralizableElement.specialization"

which will not be interpreted correct by XPath.

How can I make sure that query is interpreted as:


//Foundation.Core.Class[Foundation.Core.ModelElement.name="John"]/Foundation.Core.Gene
ralizableElement.specialization"

BR

//Mikael
 
E

Erwin Moller

hi,

try:

String query =
"//Foundation.Core.Class[Foundation.Core.ModelElement.name=\""+parent+"\"]/Foundation.Core.GeneralizableElement.specialization";

use \" if you need a " in a ""-string.

Regards,
Erwin Moller
 

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

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top