0 Favourites

How do I call 2 XML attributes with Global Variable.

  • 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/lineid="&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 :

    [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/lineid="&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/lineid="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

  • 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/lineid=Global Variable 1name=Global Variable 2/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/lineid=Global Variable 1name=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

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

  • This one is actually working when I try:

    XML.StringValue("/story/lineid="&Line&"name="&Name&"/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]
  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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)
Similar Topics Posts Views Last Post
Unread hot topic
99 10,130
karshinkoff's avatar
karshinkoff
Unread hot topic
102 6,400
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
56 4,727
MPPlantOfficial's avatar
MPPlantOfficial