PrescriptionXmlParser.java
资源名称:某公司的java培训教材 [点击查看]
上传用户:dinglihq
上传日期:2013-02-04
资源大小:99958k
文件大小:2k
源码类别:
Java编程
开发平台:
Java
- package bible.ejb.message.prescription;
- import org.xml.sax.*;
- import org.xml.sax.helpers.*;
- import java.io.*;
- import java.util.*;
- import java.text.ParseException;
- //import common.*;
- public class PrescriptionXmlParser extends DefaultHandler {
- private Prescription prescription = new Prescription();
- // Buffer for collecting data from
- // the "characters" SAX event.
- private CharArrayWriter contents = new CharArrayWriter();
- public void startElement( String namespaceURI,
- String localName,
- String qName,
- Attributes attr ) throws SAXException {
- contents.reset();
- }
- public void endElement( String namespaceURI,
- String localName,
- String qName ) throws SAXException{
- try {
- if ( localName.equals( "physician_id" ) ) {
- prescription.setPhysicianId(Integer.parseInt(contents.toString()));
- }
- if ( localName.equals( "patient_id" ) ) {
- prescription.setPatientId(Integer.parseInt(contents.toString()));
- }
- if ( localName.equals( "note" ) ) {
- prescription.setNote(contents.toString());
- }
- if ( localName.equals( "drug" ) ) {
- prescription.setDrug(contents.toString());
- }
- } catch ( Exception p)
- { System.out.println(" Here" + p.toString());
- }
- }
- public void characters( char[] ch, int start, int length )
- throws SAXException {
- contents.write( ch, start, length );
- }
- public Prescription getPrescription() {
- return prescription;
- }
- }