What is Parser?

Reply

Join Date: Oct 2004
Posts: 1
Reputation: Xaverria is an unknown quantity at this point 
Solved Threads: 0
Xaverria Xaverria is offline Offline
Newbie Poster

What is Parser?

 
0
  #1
Oct 10th, 2004
:o I have been sick for the past 2 week, thus causing me to no be able to attend my lesson on parser.But i still got an assignment to hand in..

I would like to as what is parser and how do i use it to link my java application to my web service in C#

This is one of my parser(LoginParser), somehow it does not work, can anyone tell me why?:

import java.io.*;
import javax.microedition.io.*;
import javax.microedition.lcdui.*;

import org.kxml.*;
import org.kxml.parser.*;

public class LoginParser
{
DVDReserMIDlet midlet;

public LoginParser(DVDReserMIDlet mid)
{
midlet = mid;
}

public void parse(final String URL)
{
Thread t = new Thread()
{
public void run()
{
// set up the network connection
HttpConnection hc = null;

try
{
hc = (HttpConnection)Connector.open(URL);
parse(hc.openInputStream());
}
catch (IOException ioe)
{
//mRSSListener.exception(ioe);
System.out.println("LoginParser-Error");
}
finally
{
try
{
if (hc != null)
hc.close();
}
catch (IOException ignored) {}
}
}
};
t.start();
}

public void parse(InputStream in) throws IOException
{
Reader reader = new InputStreamReader(in);
XmlParser parser = new XmlParser(reader);
ParseEvent pe = null;

String user,pass,check;
user = pass = check = null;

boolean trucking = true;

while (trucking)
{
pe = parser.read();
if (pe.getType() == Xml.START_TAG)
{
String name = pe.getName();
if (name.equals("check"))
{
while ((pe.getType() != Xml.END_TAG) || (pe.getName().equals(name) == false))
{
pe = parser.read();
if (pe.getType() == Xml.START_TAG && pe.getName().equals("username"))
{
pe = parser.read();
user = pe.getText();
}
if (pe.getType() == Xml.START_TAG && pe.getName().equals("password"))
{
pe = parser.read();
pass = pe.getText();
}
if (pe.getType() == Xml.START_TAG && pe.getName().equals("validFlg"))//xml
{
pe = parser.read();
check = pe.getText();
}
}
midlet.selectedUSER_ID = user;//store to midlet
midlet.selectedPassword = pass;
midlet.validation = check;
}
else
{
while ((pe.getType() != Xml.END_TAG) || (pe.getName().equals("html") == false))
pe = parser.read();
}
}
if (pe.getType() == Xml.END_TAG && pe.getName().equals("check"))
trucking = false;
}

if (midlet.validation.equals("SUCCESS"))
{
midlet.ChoiceSelect(1);
return;
}
else
{
midlet.ChoiceSelect(0);
return;
}
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 609
Reputation: freesoft_2000 is an unknown quantity at this point 
Solved Threads: 8
freesoft_2000 freesoft_2000 is offline Offline
Practically a Master Poster

Re: What is Parser?

 
0
  #2
Oct 17th, 2004
hi everyone,
It really depends what your defination of parser is. A parser is basically transforming one object to another thus you can change a string object to a date object or create your own parser like a document parser.

Yours Sincerely

Richard West
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC