XML Blues

0 favourites
  • 13 posts
From the Asset Store
A post apocalyptic music pack with 12 main themes and 12 in-game loops
  • Hello to everyone here at the Scirra forums.

    Thanks for taking the time to assist me with my problem.

    I'm working on a project which will be sending data back and forth between a construct 2 application and a web server which I'm using to host the application itself, as well as some php scripts and mysql datbases.

    I've chosen to use XML to receive incoming data from the server into the construct 2 application via an ajax request. This is just raw XML data, not a file that I'm sending into the application. It's more convenient for my purposes to do it this way and according to the Construct 2 manual:

    "XML must be loaded as a string with the Load action. If you have a small snippet of XML, you can paste it directly in to the action parameter. However, it's recommended to request an XML file from a server using the AJAX object."

    I've been trying to use XML directly in the action parameter, but no matter how I try, what data I input, what XPath I use, I cannot get the XML Object to return ANY data.

    I've duplicated the problem in a project file which is much less complicated than the actual project that I'm working on: XML BLues

    <img src="http://dl.dropbox.com/s/xl5f0r9e8d7cf9d/Layout.jpg" border="0">

    The Layout consists of 3 Text Objects:

    Label will always simply state 'The test was a:'

    ResultMessage is set with a default value: 'Failure'.

    If it never receives new data in the event sheet it will remain that way.

    The goal is to replace it with the contents of some XML containing the string 'Success'

    The 'Tested' Text object is initialized to the value 'To be tested', and on the start of the layout, its contents are changed to reflect the contents of a global variable which hold the XML data that is being passed into the XML object.

    <img src="http://dl.dropbox.com/s/sri8chzkjzmchld/EventSheet.jpg" border="0">

    The event sheet specifies that if the XML object returns any value other than "", that value should replace the string in the 'ResultMessage' Text object. However, no combination of XML or XPath specification that I have tried will yield any result other than "", and the result remains 'Failure'.

    <img src="http://dl.dropbox.com/s/tl0b6tku0myw2mf/Result.jpg" border="0">

    I have tried loading the XML with and without the header information. I have tired using an XPath with or wihtout including the text() component. I have tried loading the string from the result of an AJAX request containing XML. I have tried just about everything I can think of other than loading the XML from a file, which does not fit with my project, and as I stated earlier the documentation claims that working directly from a string is possible.

    Can anyone show me what I am doing wrong?

    EDIT: thanks for the help on that simple solution, now if only i could find the bug in my other code. Problem has been solved, see below.

  • The path is wrong.

    Instead of XML.StringValue("/tesult/text()")

    do XML.StringValue("/test")

  • that is REALLY strange, i dont even know how i could have entered that incorrectly but whats stranger is that its working now... i cant get it to work for the life of me in the other project i'm working on.

    Anyhow I've updated the project file to include the correction and I've noticed a few people asking for an example project using the xml object so theres one here now.

  • The string "<test>Success</test>" is not a complete XML document, it's just a tag on its own, so I would not expect it to load properly in all browsers. You should make sure you use valid and complete XML documents, which start with "<?xml ...".

  • Hello,

    this is my first Post in Scirra Forums.

    And so let me say:

    I love Constructor 2! <img src="smileys/smiley1.gif" border="0" align="middle" />

    The Manual and the Tutorials are very good - but now i have a problem with the xml plugin / xml object.

    Please look at this Screenshot:

    <img src="http://web20.shm.wissner.com/image/xml.jpg" border="0" />

    My Output ist always: "Output"

    The "Hello World" is missing.

    Can someone help me please?

  • try:

    Append newline & "Output: " & XML.StringValue("/test/text()")

  • Hi freethought78,

    thanks for your answer.

    It makes no difference...

    newline & "Output: " & XML.StringValue("/test/text()")

    newline & "Output: " & XML.StringValue("test/text()")

    newline & "Output: " & XML.StringValue("/test")

    newline & "Output: " & XML.StringValue("test")

    newline & "Output: " & XML.StringValue("//*")

    ... nothing happens...

    Hmm, is there an Bug? or i?m only stupid?

    What can i do?

    Can someone help please?

    EDIT:

    My Error was here:

    You have to Select a Layout if you create an XML-Object!?

    The XML Object is bound to a Layout.

    So if you have no Layout selected / open - Construct2 cant bound the XML Object.

    In the newest Version of Construct2 (Release 93 Beta) shows a hint if you create an XML-Object. This Message helps me to find the Solution.

    Thanks :-)

  • zedden - you can also set the XML object global so it's available in all layouts.

  • Thank you Ashley :-)

  • So I've been having a really hard time with xml too, and I've tried all the stuff on this page including what zedden did and I just can't get it to show up.

    I'm using ajax to load a file, then having an XML object load AJAX.LastData, and the text object display XML.StringValue("info").

    Here's my XML:

    <?xml version="1.0" encoding="ISO-8859-1"?>

    <info>HELLOWORLD</info>

    And before you ask:

    Yes, ajax is loading it, I can put AJAX.LastData in the text object and I get my xml back.

    Yes, I have XML set to global and in the layout.

    Yes, I've tried putting the XML directly in to no avail.

    Thanks in advance.

    ----EDIT----

    Ok I posted this a bit too soon. After messing with my stuff I managed to get the error: Extra content at the end of the document

    Do I need a closing tag for xml files?

    ----EDIT----

    Ok I solved my own problem. In XML you need to have one root node in which everything resides. I didn't know this before. Hopefully this post will at least help someone else with the same problem.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • GLaDOS9000 can you share your .capx?

  • I can but I don't think it'll be of any use....

  • I was glad to find this topic!!!

    As Ashley already said:

    " You should make sure you use valid and complete XML documents, which start with "<?xml ...". "

    First I made the same mistake and played around only with XML elements and didn't bother about the XML header. But when my PHP file echoed the missing starter line "<?xml ..." all was well

    For your info:

    For XML output in PHP I use the object XMLWriter() and the method startDocument('1.0','UTF-8') does the trick with the needed header.

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