所以我试图从一个XML文件中获取数据,但是当我通过它循环并想要出去“县名”时,我只得到第一个,然后停止。 XMl是否错误?因为我尝试过使用其他XML,并且能够将我的代码获取到我的tableview中的数据。 此致敬礼! 菲利普XML数据只显示一些
<?xml version="1.0" encoding="UTF-8"?>
<food_company>
<county>
<countyname>New York</countyname>
<city>
<cityname>New York City</cityname>
<restaurant>
<name>Dinos pizzeria</name>
<phone>01111111</phone>
<location>broadway1</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria2</name>
<phone>01111111</phone>
<location>broadway2</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria3</name>
<phone>01111111</phone>
<location>broadway3</location>
</restaurant>
</city>
<countyname>Baldwin County</countyname>
<city>
<cityname>Bay Minette</cityname>
<restaurant>
<name>Dinos pizzeria</name>
<phone>01111111</phone>
<location>broadway1</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria2</name>
<phone>01111111</phone>
<location>broadway2</location>
</restaurant>
<restaurant>
<name>Dinos pizzeria3</name>
<phone>01111111</phone>
<location>broadway3</location>
</restaurant>
</city>
</lan>
</food_company>
app.js代码:
Titanium.UI.setBackgroundColor('#E1E6EE');
// create base UI tab and root window
var win1 = Titanium.UI.createWindow({
statusBarStyle: Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
tintColor: '#FFF',
backgroundColor:'#E1E6EE',
url: 'lan.js',
tabBarHidden: true,
navBarHidden: true
});
win1.open();
county.js代码:
Ti.include('app_functions.js');
var win = Titanium.UI.currentWindow;
// create a table to display news feeds--------------------------------
var itemsTable = Ti.UI.createTableView({
top : '11%',
left : 0,
leftImage : 'taxi.png',
backgroundColor : '#DCEEDC', //E1E6EE
bottom : '0%',
// search : searchBar,
filterAttribute : 'searchFilter'
});
win.add(itemsTable);
// define xmlFeed (you can customize this with any RSS feed)
var xmlFeed = 'http://eventverket.nu/test/test5.xml';
//'http://83.254.164.137:1000/test.xml';
// create a new HTTP client object
var xhr = Ti.Network.createHTTPClient();
// this method will process the remote data
xhr.onload = function() {
// create an xml object
var xml = this.responseXML;
// create an array that will store news items for our tableView
var data = [];
var data = [];
var items = xml.documentElement.getElementsByTagName("county");
for (var i=0; i<items.length; i++) {
var row = Ti.UI.createTableViewRow({
title: items.item(i).getTextContent()
});
data.push(row);
}
itemsTable.data = data;
// when the user clicks on a row
itemsTable.addEventListener('click', function(e) {
// NEW WINDOW
var newWindow = Titanium.UI.createWindow({
backgroundColor : '#DCEEDC', //E1E6EE
statusBarStyle : Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
font : fonts[16]['normal'],
url : "stad.js",
//backButtonTitle: 'Back',
//title: e.source.title,
tabBarHidden : true,
navBarHidden : true,
tintColor : '#FFF'
});
newWindow.open();
});
};
// this method will be called if there is an error in accessing the data
xhr.onerror = function() {
// hide activity indicator
activityIndicator.hide();
// display error
alert(this.status + ': ' + this.statusText);
return false;
};
// open the remote feed
xhr.open('GET', xmlFeed);
// execute the call to the remote feed
xhr.send();
city.js代码:
Ti.include('app_functions.js');
var newWin = Titanium.UI.currentWindow;
// create a table to display news feeds--------------------------------
var itemsTable = Ti.UI.createTableView({
top : '11%',
left : 0,
leftImage : 'taxi.png',
backgroundColor : '#DCEEDC', //E1E6EE
bottom : '0%',
// search : searchBar,
filterAttribute : 'searchFilter'
});
win.add(itemsTable);
// define xmlFeed (you can customize this with any RSS feed)
var xmlFeed = 'http://eventverket.nu/test/test5.xml';
//'http://83.254.164.137:1000/test.xml';
// create a new HTTP client object
var xhr = Ti.Network.createHTTPClient();
// this method will process the remote data
xhr.onload = function() {
// create an xml object
var xml = this.responseXML;
// create an array that will store news items for our tableView
var data = [];
var items = xml.documentElement.getElementsByTagName("city");
for (var i=0; i<items.length; i++) {
var row = Ti.UI.createTableViewRow({
title: items.item(i).getTextContent() //
});
data.push(row);
}
itemsTable.data = data;
// when the user clicks on a row
itemsTable.addEventListener('click', function(e) {
// NEW WINDOW
var newWindow = Titanium.UI.createWindow({
backgroundColor : '#DCEEDC', //E1E6EE
statusBarStyle : Ti.UI.iPhone.StatusBar.LIGHT_CONTENT,
font : fonts[16]['normal'],
url : "stad.js",
//backButtonTitle: 'Back',
//title: e.source.title,
tabBarHidden : true,
navBarHidden : true,
tintColor : '#FFF'
});
});
};
// this method will be called if there is an error in accessing the data
xhr.onerror = function() {
// hide activity indicator
activityIndicator.hide();
// display error
alert(this.status + ': ' + this.statusText);
return false;
};
// open the remote feed
xhr.open('GET', xmlFeed);
// execute the call to the remote feed
xhr.send();
_你认为这个问题在不知道你的代码的情况下可以回答吗?_ ** NO **。 寻求调试帮助的问题(“为什么这个代码不工作?”)必须包含所需的行为,特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题陈述的问题对其他读者无益。 – baao
嗨迈克尔! 我很抱歉,我没有想到它通过! 这是我的代码:http:// pastie。组织/ 10397882 这里是我得到的XML数据: \t \t'VAR项目= xml.documentElement.getElementsByTagName( “县”);' \t'//通过每个回路item' \t'为( VAR I = 0; I
,请改正它,如果这是不对的。无论何时,只要您提问,请随时在您的问题中包括您的代码。这将帮助你获得答案 – baao