plz help me in xml parsing with SAX(j2me)

A

amarkinkiri

problem::::::::::I am facing problem to read the following xml file
with SAX parser(j2me).......... I am using Java wireless tool kit for
running the applications.......I want to read this xml file with SAX
parser and I have to display the contents on the phone screen...some
one plz post one example...........so that i can go through my
project......I am new to j2me coding .......so plz help me.......thanks
in advance
<sensors quantity="1">
<category name="pressure" unit="N/mm2">
<sensor id="1">
<name>sensor 1</name>
<position>description where sensor is located</position>
<range from="1.0" to="100.0"></range>
<acquisition>manual</acquisition>
<check>true</check>
</sensor>
</category>
</sensors>
 
O

Oliver Wong

problem::::::::::I am facing problem to read the following xml file
with SAX parser(j2me).......... I am using Java wireless tool kit for
running the applications.......I want to read this xml file with SAX
parser and I have to display the contents on the phone screen...some
one plz post one example...........so that i can go through my
project......I am new to j2me coding .......so plz help me.......thanks
in advance
<sensors quantity="1">
<category name="pressure" unit="N/mm2">
<sensor id="1">
<name>sensor 1</name>
<position>description where sensor is located</position>
<range from="1.0" to="100.0"></range>
<acquisition>manual</acquisition>
<check>true</check>
</sensor>
</category>
</sensors>

What's the problem? Compile error? Runtime exceptions? Something else?

- Oliver
 
A

amarkinkiri

hai,
thanks for ur reply.............I saw ur link but they are all normal
java projects....I am new to J2ME field..........could u plz post
specific example(J2ME)which reads data from the xml file and display on
the phone screen.............I am a beginner in coding.....so plz help
me.........many thanks...
bye
kinkiri
 
A

amarkinkiri

I need one example which reads xml data and displays on the phone
screen......If u have one then plz send me........parser is
SAX....thanks
 
Joined
Jan 12, 2009
Messages
1
Reaction score
0
using sax parser for reading xml file

hi
i m telling you how can you use the sax parser::

1)first of all you have to take your xml string into the form of InputSource
2)then create an instance of SAXParserFactory (coz you will create an instance of the SAXParser with this)
3)create an instance of saxparser
4)validate it
5)call "parser" method of the saxparser class which takes two parameter, that is::
a)InputSource
b)instance of the class which extends DefaultHandler class
6)now it will automatically calls the overloaded methods of the class DefaultHandler. And you only need to implement your code as you want.


I am giving you an example code, it will help you a lot.

method::
viewXML( String xmlStr )
{
try
{
byte[] xmlByteArray = xmlStr.getBytes();//k
ByteArrayInputStream xmlStream = new ByteArrayInputStream( xmlByteArray );//k
org.xml.sax.InputSource xmlReader = new org.xml.sax.InputSource( xmlStream );//k
SAXParserFactory spfactory = SAXParserFactory.newInstance();
try
{
SAXParser saxParser = spfactory.newSAXParser();//k
spfactory.setValidating(true);//k
saxParser.parse( xmlReader, new SaxParser());//k
}
catch (Throwable err)
{
err.printStackTrace ();
System.out.println("exception in SAXparser init["+err+"]");
}
}
catch(Exception e)
{
System.out.println("exception in factory init["+e+"]");
}
}



Bye tc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,008
Messages
2,570,269
Members
46,869
Latest member
TresaMcGir

Latest Threads

Top