| | |
What is Parser?
![]() |
•
•
Join Date: Oct 2004
Posts: 1
Reputation:
Solved Threads: 0
: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;
}
}
}
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;
}
}
}
![]() |
Similar Threads
- Help with LR parser algorithm (Java)
- Parser as a C++ project (C++)
- xhtml parser c code (C)
- Php parser error when xml version is mentioned (PHP)
- XHTML Complient parser? (HTML and CSS)
Other Threads in the Java Forum
- Previous Thread: saving contents of JEditorPane
- Next Thread: Need Help with ArrayList sorting
| Thread Tools | Search this Thread |
add android api applet application applications array arrays automation bank binary bluetooth chat class clear client code codesnippet collections component converter database development dice digit eclipse equation error event formatingtextintooltipjava fractal functiontesting game givemetehcodez graphics gui health html hyper ide idea image infinite input int integer j2me java javame javaprojects jni jpanel julia linux list loop looping main map method methods mobile myregfun mysql netbeans newbie nonstatic openjavafx parameter pearl php print problem program programming project recursion repositories scanner scrollbar server set size sms sort sorting spamblocker sql sqlserver state storm string superclass swing swt text-file thread threads tree windows





