XML Blues

Discussion and feedback on Construct 2

Post » Thu May 24, 2012 5:26 pm

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



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.



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'.



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.freethought782012-05-24 19:15:50
B
3
Posts: 3
Reputation: 356

Post » Thu May 24, 2012 6:23 pm

The path is wrong.
Instead of XML.StringValue("/tesult/text()")
do XML.StringValue("/test")
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Thu May 24, 2012 7:14 pm

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.
B
3
Posts: 3
Reputation: 356

Post » Thu May 24, 2012 10:33 pm

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 ...".
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Sat Jun 09, 2012 2:03 am

Hello,
this is my first Post in Scirra Forums.
And so let me say:
I love Constructor 2!

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:


My Output ist always: "Output"
The "Hello World" is missing.

Can someone help me please?


B
4
Posts: 3
Reputation: 531

Post » Sat Jun 09, 2012 8:29 am

try:

Append newline & "Output: " & XML.StringValue("/test/text()")
B
3
Posts: 3
Reputation: 356

Post » Sat Jun 09, 2012 9:50 am

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 im 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 :-)

zedden2012-06-09 10:19:36
B
4
Posts: 3
Reputation: 531

Post » Sat Jun 09, 2012 3:28 pm

@zedden - you can also set the XML object global so it's available in all layouts.
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,478

Post » Tue Jun 19, 2012 8:22 pm

Thank you Ashley :-)
B
4
Posts: 3
Reputation: 531

Post » Mon Jul 16, 2012 2:30 pm

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.GLaDOS90002012-07-16 15:04:17
B
4
Posts: 8
Reputation: 341

Next

Return to Construct 2 General

Who is online

Users browsing this forum: saiyadjin and 4 guests