OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

java and xml.



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."