[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

java and xml.


comparetoignorecase
hi,

i am new to xml and i am using it with java. i have a java program which
parses the xml file and stores the values in local variables for further
processing. my program some how doesnt seem to work. i use sax parser to
parse the xml file.

the java program is given below:

public class ReadXML extends HandlerBase
{
  String dir;
  String filename;
  public String desc1;
  public String desc2;
  public String desc3;
  public String disease;
  String tagname;

  public ReadXML()
  {
    dir=null;
    filename=null;
    desc1=null;
    desc2=null;
    desc3=null;
    disease=null;
    tagname=null;
  }
  public void setParam(String d,String f)
  {
    this.dir=d;
    this.filename=f;
  }
  public void read()
  {
     SAXParserFactory factory = SAXParserFactory.newInstance();
     try
     {
            SAXParser saxParser = factory.newSAXParser();
            saxParser.parse( new File(dir+filename), new ReadXML());
     } catch (Throwable t)
     {
            t.printStackTrace ();
     }
  }
  public void startDocument () throws SAXException
  {
       System.out.println("Start Document");
  }
  public void endDocument () throws SAXException
  {
       System.out.println("End document");
  }
  public void startElement (String name, AttributeList attrs) throws
SAXException
  {
        this.tagname=name;
  }
  public void endElement (String name) throws SAXException
  {
  }
  public void characters (char buf [], int offset, int len) throws
SAXException
  {
        String s = new String(buf, offset, len);
        if(tagname.compareToIgnoreCase("disease_type")==0)
        {
            if (!s.trim().equals(""))
            {
              this.disease=s;
            }
        }
        if(tagname.compareToIgnoreCase("description1")==0)
        {
           if (!s.trim().equals(""))
           {
             this.desc1=s;
           }
        }
        if(tagname.compareToIgnoreCase("description2")==0)
        {
          if (!s.trim().equals(""))
          {
            this.desc2=s;
          }
        }
        if(tagname.compareToIgnoreCase("description3")==0)
        {
          if (!s.trim().equals(""))
          {
            this.desc3=s;
          }
        }
  }
  public String getDesc1()
  {
    return desc1;// this returns a null value
  }
  public String getDesc2()
  {
    return desc2;// returns a null value
  }
  public String getDesc3()
  {
    return desc3;//returns a null value
  }
  public String getDisease()
  {
    return disease;
  }
}


all the get methods return a null value and that shouldnt be the case. i
dont know where i am wrong. 

thanks and regards
priya


"THIS E-MAIL MESSAGE ALONG WITH ANY ATTACHMENTS IS INTENDED ONLY FOR THE
ADDRESSEE and may contain confidential and privileged information.
If the reader of this message is not the intended recipient,
you are notified that any dissemination, distribution or copy of this 
communication is strictly Prohibited. 
If you have received this message by error, please notify us 
immediately, return the original mail to the sender and delete the 
message from your system."


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.