Reading XML file

Hi allPlease help me :(I have "test.xml" file and I put it in the src folder of my project, and I download kxml parser.My question is:How can I read this xml file and using its contents in my application?thanks in advance, and please help me
[283 byte] By [primrosea] at [2007-11-27 7:55:54]
# 1
any one please help me
primrosea at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 2
Try this links : http://developers.sun.com/mobility/midp/articles/parsingxml/and this : http://kxml.objectweb.org/software/downloads/current/kxml-doc.zip
find_suvro@SDNa at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 3
the xml file must be put into the localhost or in a server. then it will work
Sreeram_MPa at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 4

> 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.

find_suvro@SDNa at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 5
did you try to put your xml file in the res folder and calling it with" /myxml.xml"?
suparenoa at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 6

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

primrosea at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 7
so now give the dukes to your favorite helper to close the thread...
suparenoa at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 8
Ok but sorry till now I don't get full help !!thanks
primrosea at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 9

> 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

suparenoa at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 10

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

primrosea at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...
# 11
Dukes : http://developers.sun.com/forums/dukestars/index.jsp
find_suvro@SDNa at 2007-7-12 19:37:23 > top of Java-index,Java Mobility Forums,Java ME Technologies...