How do I call 2 XML attributes with Global Variable.

Get help using Construct 2

Post » Mon Apr 20, 2015 5:05 pm

Hello,
let me explain my problem :

I use XML on my project.

<story>
<line id="01">hello</line>
<line id="02">I love Construct</line>
<line id="03">But I'm a noob</line>
</story>


I call line "id" with this xpath expression using a global variable :

XML.StringValue("/story/line[@id="&Global Variable&"]/text()")

Here an exemple made by @korbaach few days ago : http://s000.tinyupload.com/index.php?fi%20...%207337387723

It works great. Perfect !

NOW MY PROBLEM :

I want to do the same, but with 2 XML attributes :

<story>
<line id="01" name ="Cat">hello i'm Cat</line>
<line id="01" name ="Dog">hello i'm Dog</line>
<line id="02" name ="Cat">Cat loves Construct</line>
<line id="02" name ="Dog">Dog loves Construct</line>
</story>


And I want to call line using both attributes, "id" and "name" with two differents global variable :

XML.StringValue("/story/line[@id="&Global Variable 1&"][@name="&Global Variable 2&"]/text()")

And it's not working. And I don't know why.

I don't think it's a xml synthax error, when I try to call directly "id" and "name" without Global Variable, it works fine

XML.StringValue("/story/line[@id="01"][@name="Dog"]/text()") => OK

I've tried to make it clear, but not easy to explain, hope you can understand me and please tell me if you have an idea of what i'm doing wrong !
Thank you ^^


EDIT :
here a Capx of my problem :
http://www.vintehin.fr/construct/xml_test.capx
Last edited by Vintehin on Mon Apr 20, 2015 6:41 pm, edited 1 time in total.
B
9
S
2
Posts: 15
Reputation: 625

Post » Mon Apr 20, 2015 5:13 pm

If the global variable is a text I don't think there is a need for the extra "
Try if this works:

XML.StringValue("/story/line[@id=Global Variable 1][@name=Global Variable 2]/text()")
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Apr 20, 2015 6:40 pm

LittleStain wrote:If the global variable is a text I don't think there is a need for the extra "
Try if this works:

XML.StringValue("/story/line[@id=Global Variable 1][@name=Global Variable 2]/text()")


Thx for helping me.

Still can't make it work.

I've made a little capx if someone want to take a look :
http://www.vintehin.fr/construct/xml_test.capx
B
9
S
2
Posts: 15
Reputation: 625

Post » Mon Apr 20, 2015 7:04 pm

old: XML.StringValue("/story/line[@id="&Line&"][@name="&Name&"/text()")

new: XML.StringValue("/story/line[@id="&Line&"][@name='"&Name&"']/text()")

To treat the Line variable as an integer, make sure there are no single-quotes (so you don't need to prefix it with a zero), otherwise it would have to be Text. For text however you do need the single-quotes. You were missing the single quotes and the end square-bracket around Name.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994

Post » Mon Apr 20, 2015 7:16 pm

This one is actually working when I try:

XML.StringValue("/story/line[@id="&Line&"][@name="&Name&" ]/text()")

Very unexpected, but the one with double quotes isn't?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Mon Apr 20, 2015 7:26 pm

Actually, you should always have double-quotes around XML attributes. So the query should look like this :

Code: Select all
XML.StringValue("/story/line[@id="""&Line&"""][@name="""&Name&"""]/text()")
B
71
S
30
G
25
Posts: 984
Reputation: 19,503

Post » Mon Apr 20, 2015 7:38 pm

It's working ! :D

Thanks all of you, it was a double-quotes error indeed !

Here the working capx if someone have the same problem one day :
http://www.vintehin.fr/construct/xml_ok.capx
B
9
S
2
Posts: 15
Reputation: 625


Return to How do I....?

Who is online

Users browsing this forum: kalibark2, Yahoo [Bot] and 20 guests