> the xml file must be put into the localhost or in a
> server. then it will work
Not necessarily dude. Are u trying to say that am not able to use any file (or some XML file) unless I download it from some remote server !!!!
You should have asked to keep it in the resources folder rather if u are making it in Sun Java WTK directory standard. But that solely depends on which tool u are using to make that project.
Many Thanks for all
I do the following:
InputStream is = this.getClass().getResourceAsStream("RR.xml");
and then call function to parse the file after reading it:
parseRssFeedXml(is);
and the declartion of the function as
public void parseRssFeedXml(InputStream is) throws IOException, XmlPullParserException {
/** Initialize item collection */
m_rssFeed.getItems().removeAllElements();
/** Initialize XML parser and parse RSS XML */
KXmlParser parser = new KXmlParser();
parser.setInput( new InputStreamReader(is) );
/** RSS item properties */
String title = null;
String description = null;
String link = null;
/** <?xml...*/
parser.nextTag();
/** Various tags... Wait for the <item> tag */
parser.require(parser.START_TAG, null, null);
while(!"item".equals(parser.getName()) )
{
/** Check if document doesn't include any item tags */
if( parser.next() == parser.END_DOCUMENT )
throw new IOException("No items in RSS feed!");
}
/** Parse <item> tags */
do {
parser.require(parser.START_TAG, null, null);
/** Initialize properties */
title = "";
description = "";
link = "";
/** One <item> tag handling*/
while (parser.nextTag() != parser.END_TAG)
{
parser.require(parser.START_TAG, null, null);
String name = parser.getName();
String text = parser.nextText();
/** Save item property values */
if (name.equals("title"))
title = text;
else if (name.equals("description"))
description = text;
else if (name.equals("link"))
link = text;
parser.require(parser.END_TAG, null, name);
}
/** Debugging information */
System.out.println ("Title:" + title);
System.out.println ("Link:" + link);
System.out.println ("Description: " + description);
/** Create new RSS item and add it do RSS document's item
* collection
*/
RssItem rssItem = new RssItem(title, link, description);
m_rssFeed.getItems().addElement( rssItem );
parser.nextTag();
} while("item".equals(parser.getName()));
}
BTW I get this code which is of RSS project but insted of reading the xml file from url, I read it from an existing file that stored in the src folder.
thanks again
> Ok but sorry till now I don't get full help !!
>
> thanks
your first question was:
> How can I read this xml file and using its contents in my application?
somebody gave you the solution. if you have problem for parsing, give the dukes
and open a new one...
you it's easy to say "don't get full help".
for example, i start a thread with title "Problem with reading txt"
somebody gave me the solution (getResourceAsStream(...),etc...) and i'm not satisfied
because my data are written in chinese and my telephone doesn't display them correctly
so i continue this thread etc, etc... and i will never give the dukes to the first person who
help me to read the txt file
i hope you see what i mean :)
sup@reno
ok supareno
Aafter you replaying me, when you asked me to give the favorate helper dukes and close the thread, I gave one helper one duke and now I have 2 dukes. But really, I don't know what the benefet of dukes!!. Since this the first time I use the Dukes in my thread !!
So, can you tell me more about it, please? :)
best regards