- Forum posts: 1
Feb 12, 2016, 2:16:46 PM via Website
Feb 12, 2016 2:16:46 PM via Website
Hello. I'm a quite new developer. I am programming by Android Studio. I am not able to fix the xml code from server to my app. (parse XML data into a ListView)
Here is my java code
public class SitesXmlPullParser {
static final String KEY_SITE = "array";
static final String KEY_TITLE = "title";
static final String KEY_PERIODITA = "periodIta";
static final String KEY_LINKZIP = "linkzip";
static final String KEY_IMAGE_URL = "image";
public static List<AtlantisSite> getAtlantisSiteFromFile(Context ctx) {
// List of AtlantisSite.java that we will return
List<AtlantisSite> AtlantisSite;
AtlantisSite = new ArrayList<AtlantisSite>();
// temp holder for current AtlantisSite while parsing (crate object)
AtlantisSite curAtlantisSite = null;
// temp holder for current text value while parsing
String curText = "";
try {
// Get our factory and PullParser
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
XmlPullParser xpp = factory.newPullParser();
// Open up InputStream and Reader of our file.
FileInputStream fis = ctx.openFileInput("issues.plist");
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
// point the parser to our file.
xpp.setInput(reader);
// get initial eventType
int eventType = xpp.getEventType();
// Loop through pull events until we reach END_DOCUMENT
while (eventType != XmlPullParser.END_DOCUMENT) {
// Get the current tag
String tagname = xpp.getName();
// React to different event types appropriately
switch (eventType) {
case XmlPullParser.START_TAG:
if (tagname.equalsIgnoreCase(KEY_SITE)) {
// If we are starting a new <site> block we need
//a new StackSite object to represent it
curAtlantisSite= new AtlantisSite();
}
break;
case XmlPullParser.TEXT:
//grab the current text so we can use it in END_TAG event
curText = xpp.getText();
break;
case XmlPullParser.END_TAG:
if (tagname.equalsIgnoreCase(KEY_SITE)) {
// if </site> then we are done with current Site
// add it to the list.
AtlantisSite.add(curAtlantisSite);
} else if (tagname.equalsIgnoreCase(KEY_TITLE)) {
// if </name> use setName() on curSite
curAtlantisSite.setTitle(curText);
} else if (tagname.equalsIgnoreCase(KEY_PERIODITA)) {
// if </link> use setLink() on curSite
curAtlantisSite.setperiodIta(curText);
} else if (tagname.equalsIgnoreCase(KEY_LINKZIP)) {
// if </about> use setAbout() on curSite
curAtlantisSite.setlinkzip(curText);
} else if (tagname.equalsIgnoreCase(KEY_IMAGE_URL)) {
// if </image> use setImgUrl() on curSite
curAtlantisSite.setImgUrl(curText);
}
break;
default:
break;
}
//move on to next iteration
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
}
// return the populated list.
return AtlantisSite;
}
}
and here is the xml source
a qplist version="1.0">
array>
dict>
key>Name
string>03_2012
key>Title
string>Atlantis 3 2012
key>PeriodIta
string>Ottobre / Novembre
key>PeriodEng
string>October / November
key>Date
date>2013-02-01T10:00:00Z
key>Cover
string>
http.....
string>
key>SummaryEng
string>
The bimonthly Italian American Magazine is always available on paper and you can subscribe it using purchase instruction on website. In this issue
key>SummaryIta
string>
La rivista bimestrale italo-americana, è sempre disponibile anche su carta e per riceverla è necessario abbonarsi utilizzando la procedura d
/string>
key>PriceIta
string>gratis
key>PriceEng
string>free
key>Content
string>
http:....
/string>
/dict>
dict>...
dict>...
dict>...
array>
plist>uote goes here
I am not able to fix it. can somebody give me some advices?
— modified on Feb 12, 2016, 2:29:53 PM
Recommended editorial content
With your consent, external content is loaded here.
By clicking on the button above, you agree that external content may be displayed to you. Personal data may be transmitted to third-party providers in the process. You can find more information about this in our Privacy Policy.