How do I call 2 XML attributes with Global Variable.

0 favourites
  • 7 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • Hello,

    let me explain my problem :

    I use XML on my project.

    [quote:2r052iec]<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/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 :

    [quote:2r052iec]<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/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/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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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/text()")

  • 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/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

  • old: XML.StringValue("/story/line[@name="&Name&"/text()") new: XML.StringValue("/story/line/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.

  • This one is actually working when I try:

    XML.StringValue("/story/line/text()")

    Very unexpected, but the one with double quotes isn't?

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

    XML.StringValue("/story/line[@id="""&Line&"""][@name="""&Name&"""]/text()")[/code:1xgrz275]
  • It's working !

    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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)