我正在 Appcelerator Titanium 中开发一个应用程序。我面临的问题是,当我第一次在单击按钮时解析特定的 XML 时,它工作正常,但是如果我重新单击按钮,则应该再次解析 XML,这不会发生。在日志中,我可以在重新形成的 XML 中看到更新的值,但是当我尝试解析它时,解析器中使用的变量会保留它们的值。他们没有得到更新。更新解析器的变量值要做什么?
解析代码:
if(xml.getElementsByTagName("d:user_id").length>0)
{
Ti.App.information.user_id = xml.getElementsByTagName("d:user_id").item(0).text;
Ti.App.information.organization_id=xml.getElementsByTagName("d:organization_id").item(0).text;
Ti.App.information.uname=xml.getElementsByTagName("d:name").item(0).text;
Ti.App.information.Lpassword=xml.getElementsByTagName("d:password").item(0).text;
Ti.App.information.Lemail_id=xml.getElementsByTagName("d:email_id").item(0).text;
Ti.App.information.is_valid=xml.getElementsByTagName("d:is_valid").item(0).text;
}
这是我使用Ti.App.information.is_valid变量的函数:
function checkCredential()
{
if(Ti.Utils.md5HexDigest(txtPasswordLogin.value)==Ti.App.information.Lpassword && txtEmailLogin.value == Ti.App.information.Lemail_id)
{
activityIndicator.hide();
//alert("welcome");
//Login.close();
if(Ti.App.information.is_valid == 'true')
{
//Ti.API.info("..........Login Success........Getting Approved Forms..........");
Ti.App.information.is_valid='';
//alert(Ti.App.is_valid);
// Titanium.include('Login.js');
// Login.open();
Ti.App.information.is_valid = '';
Titanium.include('Home.js');
Home.open();
}
else
{
// var a = Titanium.UI.createAlertdialogScreen({title:'Access Denied!'});
Ti.App.information.is_valid='';
//alert(Ti.App.is_valid);
myAlert.title = 'Access Denied!';
myAlert.setMessage('You are not authorized. Please contact Administrator.');
myAlert.addEventListener('click', function(e){
// Titanium.include('Login.js');
// Login.open();
Login.close();
});
myAlert.show();
}
}
else
{
Ti.App.information.is_valid='';
//alert(Ti.App.is_valid);
activityIndicator.hide();
myAlert.title = 'Invalid Login!';
myAlert.setMessage('The email address or password you entered is incorrect.');
myAlert.show();
// Titanium.include('Login.js');
// Login.open();
// alert("Please enter a correct password.");
}
}
变量在app.js文件中声明:
Ti.App.information={base_url:'',uid:'',password:'',EmailId:'',pass:'',user_id:'',organization_id:'',uname:'',Lpassword:'',Lemail_id:'',is_valid:''};
Ti.App.authentication=false;
Ti.App.formid;
Ti.App.guid;
Ti.App.mydata={_guid:'',status:true,networkStatus:true};
Ti.App.formurl={burl:''};
Ti.App.glocation={longitude:'',latitude:'',gloc:''};
Ti.App.gloc;
这是要解析的示例 XML 文件:
<feed xml:base="http://webdevhost.servehttp.com/iPhoneDataEntryService/iPhoneDataEntryDataService.svc/" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns="http://www.w3.org/2005/Atom">
<title type="text">users</title>
<id>http://webdevhost.servehttp.com/iPhoneDataEntryService/iPhoneDataEntryDataService.svc/users</id>
<updated>2012-10-26T04:05:48Z</updated>
<link rel="self" title="users" href="users" />
<entry>
<id>http://webdevhost.servehttp.com/iPhoneDataEntryService/iPhoneDataEntryDataService.svc/users(34L)</id>
<title type="text"></title>
<updated>2012-10-26T04:05:48Z</updated>
<author>
<name />
</author>
<link rel="edit" title="user" href="users(34L)" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/user_type" type="application/atom+xml;type=entry" title="user_type" href="users(34L)/user_type" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/organization" type="application/atom+xml;type=entry" title="organization" href="users(34L)/organization" />
<link rel="http://schemas.microsoft.com/ado/2007/08/dataservices/related/form_data" type="application/atom+xml;type=feed" title="form_data" href="users(34L)/form_data" />
<category term="iPhoneDataEntryModel.user" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" />
<content type="application/xml">
<m:properties>
<d:user_id m:type="Edm.Int64">34</d:user_id>
<d:organization_id m:type="Edm.Int64">1</d:organization_id>
<d:name>test</d:name>
<d:password>16690502e26791e97c6c4743d2d4cb9a</d:password>
<d:email_id>ad@ad.com</d:email_id>
<d:user_type_id m:type="Edm.Int32">3</d:user_type_id>
<d:is_valid m:type="Edm.Boolean">true</d:is_valid>
<d:registration_date m:type="Edm.DateTime">2012-10-18T10:33:13</d:registration_date>
</m:properties>
</content>
</entry>
</feed>
d:is_valid是我必须在单击按钮时每隔一段时间解析的标签。
问题是,即使在重新调用解析器之后,该变量仍保留其值。