×

Discussion Board

Results 1 to 15 of 19

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    11

    Parsing wbxml file to xml file using kxml parser

    hi,

    I am parsing xml file to wbxml using kxml parser but while parsing back the wbxml file to xml file, I getting the error

    java.io.IOException: Curr. only CP0 supported
    at org.kxml.wap.WbxmlParser.peek(+302)
    at org.kxml.kdom.Node.parse(+6)
    at org.kxml.kdom.Document.parse(+5)
    at XMLtoWBXML.getXMLStream(XMLtoWBXML.java:115)
    at XMLtoWBXML.startApp(XMLtoWBXML.java:67)
    at javax.microedition.midlet.MIDletProxy.startApp(MIDletProxy.java:44)
    at com.sun.midp.midlet.Scheduler.schedule(Scheduler.java:375)
    at com.sun.midp.main.Main.runLocalClass(Main.java:477)
    at com.sun.midp.main.Main.main(Main.java:130)

    xml file that i am parsing is:

    <?xml version="1.0" encoding="utf-8"?>
    <Sync xmlns="AirSync:" xmlns:A="POOMCONTACTS:">
    <Collections>
    <Collection>
    <Class>Contacts</Class>
    <SyncKey>{6A374473-D63E-45FA-8556-129C8C1C3CFA}11</SyncKey>
    <Status>1</Status>
    <Commands>
    <Add>
    <ServerId>rid:01c133474e27d04faba48d02078cf41d00000090e129
    </ServerId>
    <ApplicationData>
    <A:FileAs>Mouse, Mickey</A:FileAs>
    <A:FirstName>Mickey</A:FirstName>
    <A:LastName>Mouse</A:LastName>
    <A:BusinessPhoneNumber>(425) 555-1212</A:BusinessPhoneNumber>
    </ApplicationData>
    </Add>
    </Commands>
    </Collection>
    </Collections>
    </Sync>

    the code which i am using for Parsing wbxml to xml:
    public byte[] getXML( byte[] wbxmlData ) { // wbxml to xml
    try {

    ByteArrayInputStream in = new ByteArrayInputStream(wbxmlData);
    AbstractXmlParser parser = new WbxmlParser(in);

    Document document = new Document ();
    document.parse(parser); (error pointing here)
    in.close();
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    XmlWriter writer = new XmlWriter(new OutputStreamWriter( out ) );
    document.write(writer);
    writer.close();

    wbxmlData = out.toString().getBytes();
    out.close();

    }
    catch(IOException ioe){
    System.out.println(" in ioe: ");
    ioe.printStackTrace();
    }
    catch (Exception e)
    {e.printStackTrace();}
    return wbxmlData;
    }

    also i want to parse data between the tags <ApplicationData>
    <A:FileAs>Mouse, Mickey</A:FileAs>
    <A:FirstName>Mickey</A:FirstName>
    <A:LastName>Mouse</A:LastName>
    <A:BusinessPhoneNumber>(425) 555-1212</A:BusinessPhoneNumber>
    </ApplicationData>

    where A is xml namespace.

  2. #2
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    And how do your WBXML codepages look like? Is there any reason to decode the WBXML to XML again at all?

  3. #3
    Registered User
    Join Date
    May 2007
    Posts
    11

    Re: Parsing wbxml file to xml file using kxml parser

    the output of xml to wbxml will in this format, here i am not able to make out the code pages

    wbxml ?Sync xmlns xmlns:A Collections Collection Class SyncKey Status Commands Add ServerId ApplicationData A:FileAs A:FirstName A:LastName A:BusinessPhoneNumber 


    Ä AirSync:  POOMCONTACTS: 


    D


    D


    D*Contacts 


    D0{6A374473-D63E-45FA-8556-129C8C1C3CFA}11 


    D81 


    D?


    DH


    DLrid:01c133474e27d04faba48d02078cf41d00000090e129


    


    DU


    DeMouse, Mickey 


    DnMickey 


    DzMouse 


    D?(425) 555-1212 


    


    


    


    


    


    


    but i just want to take data present in between <ApplicationData>
    <A:FileAs>Mouse, Mickey</A:FileAs>
    <A:FirstName>Mickey</A:FirstName>
    <A:LastName>Mouse</A:LastName>
    <A:BusinessPhoneNumber>(425) 555-1212</A:BusinessPhoneNumber>
    </ApplicationData>

    but how to take (parse) this firstname-Mickey, lastname-Mouse, phonenumber->(425) 555-1212 in wbxml is my need. no need to convert it back to xml format.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    I do not understand you. Could you please elaborate a bit more and/or try again. Have you converted the data to WBXML? Then you have defined at least one TAG_TABLE (string array which contains the tag to id mapping).

  5. #5
    Registered User
    Join Date
    May 2007
    Posts
    11

    Re: Parsing wbxml file to xml file using kxml parser

    My requirement is , i need to parse the <sync> </sync> xml file to wbxml file and fetch the data present in between tags<Application> </Application> and store firstname, lastname and phone number in mobiles pim.

    i m using kxml parser to parse the data and program goes like this:

    try{
    ByteArrayInputStream in = new ByteArrayInputStream(resultbyte);// resultbyte is wbxml form of above <sync> </sync> xml file.
    WbxmlParser parser = new WbxmlParser(in);

    parseAddressTag( parser );

    List list = new List(" contact List", Choice.IMPLICIT);
    for(int i =0; i<vector.size(); i++){
    list.append(vector.elementAt(i).toString().trim(),null);
    System.out.println(" vec " + vector.elementAt(i).toString().trim());
    }
    Display.getDisplay(this).setCurrent(list);

    } catch (IOException ioe) {

    System.err.println("XML Parsing Error: " + ioe);
    ioe.printStackTrace();
    }
    }

    }
    public void parseAddressTag( WbxmlParser parser ) throws IOException {
    ParseEvent event = null;

    event = parser.read();

    while ((event = parser.peek()).getType() != Xml.END_DOCUMENT) {

    String name = event.getName();

    int type = event.getType();
    if (type == Xml.END_TAG && name.equals("address")) {
    event = null;
    name = null;
    return;
    }
    event = parser.read();

    if (type != Xml.START_TAG) {

    event = null;
    continue;
    }
    ParseEvent next = parser.read();
    if (next.getType() != Xml.TEXT) {
    event = null;
    next = null;
    continue;
    }
    String text = next.getText();

    if(name.equals("Firstname")){
    vector.addElement(text);
    }
    List list = new List(" Conacts List", Choice.IMPLICIT);
    for(int i =0; i<vector.size(); i++){
    list.append(vector.elementAt(i).toString().trim(),null);
    }
    Display.getDisplay(this).setCurrent(list);

    System.err.println( name + ": " + text );

    event = null;
    text = null;
    next = null;
    }


    while parsing that i m getting above reported error "java.io.IOException: Curr. only CP0 supported." if i parse any simple wbxml file it parses and print the data correctly. ex
    xml file:
    <address_book>
    <info>
    <owner>Robert Cadena</owner>
    </info>
    <address>
    <name>Robert Cadena</name>
    <street_1>5555 Fake Street </street_1>
    <street_2>Suit 202</street_2>
    <city>Fake City</city>
    <state>CA</state>
    <zipcode>900099</zipcode>
    </address>
    <address>
    <name>Fake Name</name>
    <street_1>3232 Another Street </street_1>
    <city>Another City</city>
    <state>TX</state>
    <zipcode>79999</zipcode>
    </address>

    </address_book>

    wbxml:
    Jaddress_book info owner address name street_1 street_2 city state zipcode D 


    


    D
    



    DRobert Cadena 


    


    D


    D Robert Cadena 


    D%5555 Fake Street 


    D.Suit 202 


    D7Fake City 


    D<CA 


    DB900099 


    


    D


    D Fake Name 


    D%3232 Another Street 


    D7Another City 


    D<TX 


    DB79999 


    





    

    usage of namespace is posing some problem to parse for <sync> xml file?

    i m not able to create the tag_table, Attribute_table because i need to parse the wbxml data.

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    Sorry, still not get it: Who created the WBXML file? You or somebody else?

Similar Threads

  1. XML Parser in C++
    By mrinal_malhotra in forum Symbian
    Replies: 4
    Last Post: 2008-11-10, 13:22
  2. Replies: 1
    Last Post: 2005-05-26, 14:22
  3. XML parsing problem in Nokia 12
    By codekiller in forum Nokia M2M
    Replies: 2
    Last Post: 2005-04-26, 09:01
  4. Replies: 0
    Last Post: 2002-06-10, 12:24
  5. XML parsing
    By Nokia_Archive in forum Symbian Tools & SDKs
    Replies: 1
    Last Post: 2002-05-31, 19:01

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×