Reputation: 37
I have started development on Windows Phone with Appcelerator. I am using my Android's code as a base and while doing that I am facing a particular issue with XML parsing. This is the XML string :
<returnXml>
<methodStatus>
<statusType>success</statusType>
</methodStatus>
<parametersReturn />
</returnXml>
And this is the code I am trying to run :
var xml = Ti.XML.parseString(xmlString);
var statusType = xml.evaluate("/returnXml/methodStatus/statusType").item(0).text;
The above code works fine on Android, but on Windows Phone I am getting :
TypeError: xml.evaluate is not a function
So I tried to use the following code instead :
getElementsByTagName("statusType")
But it seems that either the functions are not supported for Windows phone or I am doing some mistake here. Should I be doing something else or should I look for external XML Parser library for JavaScript? If so, please guide.
Upvotes: 0
Views: 62
Reputation: 2907
We should support the Ti.XML.Document.evaluate function (and getElementsByName). To see our unit tests around the Ti.XML API, you can look here: https://github.com/appcelerator/titanium_mobile_windows/blob/master/Examples/NMocha/src/Assets/ti.xml.test.js
It's possible that we're not testing a variant of XPath or the API that you are using. If so, maybe some of what we test there can help you workaround the issue temporarily until we can fix what's breaking? It'd be helpful for you to file a buh report in JIRA with details on what version of the SDK you're using: https://jira.appcelerator.org/secure/CreateIssue!default.jspa
For now, I've created a PR with a new unit test attempting to recreate your issue: https://github.com/appcelerator/titanium_mobile_windows/pull/575 It'd be good to know if you have suggestions for improving that test.
I can say that your code snippet should fail on trying to access the text value since the property for getting the "text" is textContent, so it'd be:
var statusType = xml.evaluate("/returnXml/methodStatus/statusType").item(0).textContent;
See http://docs.appcelerator.com/platform/latest/#!/api/Titanium.XML.Node-property-textContent
Though you could just do it all in one shot in the XPath expression:
var statusType = xml.evaluate("/returnXml/methodStatus/statusType[1]/text()");
Upvotes: 1