944,116 Members | Top Members by Rank

Oct 10th, 2004
0

What is Parser?

Expand Post »
: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;
		}
	}
}
Last edited by peter_budo; May 20th, 2010 at 5:32 pm. Reason: Adding code tags to old post
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Xaverria is offline Offline
1 posts
since Oct 2004
Oct 17th, 2004
0

Re: What is Parser?

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
Reputation Points: 25
Solved Threads: 10
Practically a Master Poster
freesoft_2000 is offline Offline
623 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Next Thread in Mobile Development Forum Timeline: Another "cannot find symbol" compiling error





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC