BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 05-28-2008, 05:28 AM   #1
hibbert
Thumbs Must Hurt
 
Join Date: May 2007
Location: berlin, germany
Model: 8310
PIN: N/A
Carrier: vodafone
Posts: 163
Default Parse XML

Please Login to Remove!

xxx9834; Hello again xxx9835; ;)
i try to parse a XML string bo doing the following:
PHP Code:
private void parseDocument() {

        
//get a factory
        
SAXParserFactory spf SAXParserFactory.newInstance();
        try {

            
//get a new instance of parser
            
SAXParser sp spf.newSAXParser();

            
//parse the file and also register this class for call backs
            
sp.parse("employees.xml"this);

        }catch(
SAXException se) {
            
se.printStackTrace();
        }catch(
ParserConfigurationException pce) {
            
pce.printStackTrace();
        }catch (
IOException ie) {
            
ie.printStackTrace();
        }
    } 
PHP Code:
//Event Handlers
    
public void startElement(String uriString localNameString qName,
        
Attributes attributesthrows SAXException {
        
//reset
        
tempVal "";
        if(
qName.equalsIgnoreCase("Employee")) {
            
//create a new instance of employee
            
tempEmp = new Employee();
            
tempEmp.setType(attributes.getValue("type"));
        }
    }


    public 
void characters(charxxx91;xxx93; chint startint lengththrows SAXException {
        
tempVal = new String(ch,start,length);
    }

    public 
void endElement(String uriString localName,
        
String qNamethrows SAXException {

        if(
qName.equalsIgnoreCase("Employee")) {
            
//add it to the list
            
myEmpls.add(tempEmp);

        }else if (
qName.equalsIgnoreCase("Name")) {
            
tempEmp.setName(tempVal);
        }else if (
qName.equalsIgnoreCase("Id")) {
            
tempEmp.setId(Integer.parseInt(tempVal));
        }else if (
qName.equalsIgnoreCase("Age")) {
            
tempEmp.setAge(Integer.parseInt(tempVal));
        }

    } 
PHP Code:
    public class Employee {
        private 
String type "";
        private 
String name "";
        private 
String id "";
        private 
String age "";
        
        public 
void setType(String _type) {
            
type _type;
        }
        
        public 
void setName(String _name) {
            
name _name;
        }
        
        public 
void setId(String _id) {
            
id _id;
        }
        
        public 
void setAge(String _age) {
            
age _age;
        }
    } 
My problem is, that the compiler will not do wat i want ;)
Quote:
Originally Posted by compiler
Symbol : method parse(java.lang.String,Project1)
location: class net.rim.device.api.xml.parsers.SAXParser
sp.parse("employees.xml", this);
i also have these one here at the begining of my source:
PHP Code:
import net.rim.device.api.xml.parsers.SAXParserFactory;
import net.rim.device.api.xml.parsers.*;
import net.rim.device.api.xml.parsers.SAXParser.*; 
So whats wrong?
what do i need to change if i want to parse a XML-string instead of a XML-File?

thanks hibbert
__________________
My English is so bad, that makes me nobody so quickly after
Offline  
Old 05-28-2008, 06:06 AM   #2
simon.hain
CrackBerry Addict
 
Join Date: Apr 2005
Location: hamburg, germany
Model: 8900
Carrier: o2
Posts: 838
Default

you have to read the file first. See org.xml.sax.InputSource for applicable input, in most cases a bytestream is the way to go.
__________________
java developer, Devinto, hamburg/germany
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


NEW Fujitsu TX100 S3 Server Intel Xeon E3-1220v2 3.1GHz 4GB 1TB NIB RAID 0,1,10 picture

NEW Fujitsu TX100 S3 Server Intel Xeon E3-1220v2 3.1GHz 4GB 1TB NIB RAID 0,1,10

$249.99



EMC2 HPE-S HPES Server picture

EMC2 HPE-S HPES Server

$465.00



Server SE-SS 07020 Server Express Single Drop-In - NEW - COMPLETE - Genuine OEM picture

Server SE-SS 07020 Server Express Single Drop-In - NEW - COMPLETE - Genuine OEM

$199.99



Server - 92020 - Double Dip Server picture

Server - 92020 - Double Dip Server

$348.84



DIGI EtherLite 160 16-Port Terminal Server,PN: (1P)50000986-01 P picture

DIGI EtherLite 160 16-Port Terminal Server,PN: (1P)50000986-01 P

$260.00



DELL PowerEdge R310 Server picture

DELL PowerEdge R310 Server

$80.00







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.