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?: :confused:

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;
		}
	}
}

Edited by peter_budo: Adding code tags to old post

2
Contributors
1
Reply
2
Views
13 Years
Discussion Span
Last Post by freesoft_2000
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.