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]

RE: [xml-dev] java and xml.



Where you have 

            saxParser.parse( new File(dir+filename), new ReadXML());

you should have 

            saxParser.parse( new File(dir+filename), this );

What you are doing is creating two instances of ReadXML.  All the values are
read into the second instance (the new ReadXML() one) but you are trying to
retrieve the values from the first instance.


> -----Original Message-----
> From:	S, Sripriya (MED) [SMTP:SripriyaS@geind.ge.com]
> Sent:	16 November 2001 9:29 PM
> To:	James Clark
> Cc:	xml-dev@lists.xml.org
> Subject:	[xml-dev] 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."
> 
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
This communication is confidential and may contain privileged material.
If you are not the intended recipient you must not use, disclose, copy or retain it.
If you have received it in error please immediately notify me by return email
and delete the emails.
Thank you.