×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    i want to convert wbxml into xml ,what wrong in this codes

    import java.io.*;

    import org.kxml.io.*;
    import org.kxml.kdom.*;
    import org.kxml.parser.*;
    import org.kxml.wap.*;

    public class Test2 {

    public byte[] getXMLStream( byte[] wbxmlData ) {
    try {
    // Construct an InputStream on byte[]
    // to be used by WbxmlParser.
    ByteArrayInputStream in = new ByteArrayInputStream(wbxmlData);
    AbstractXmlParser parser = new WbxmlParser(in);

    // Construct a DOM Document to parse WBXML.
    Document document = new Document ();
    document.parse(parser);
    in.close();

    // Make a Writer on which XmlWriter can write.
    CharArrayWriter out = new CharArrayWriter();
    AbstractXmlWriter writer = new XmlWriter(out);
    document.write(writer);
    writer.close();

    // Get XML byte[] from CharArrayWriter filled by XmlWriter.
    wbxmlData = out.toString().getBytes();
    out.close();

    }//try
    catch (Exception e) {e.printStackTrace();}
    return wbxmlData;
    }//getXMLStream


    public byte[] getWBXMLStream(byte[] xmlData) {
    try {
    // Construct an InputStreamReader on ByterArrayInputStream.
    InputStreamReader in = new InputStreamReader(new ByteArrayInputStream(xmlData));

    // Make parser using this Reader.
    XmlParser parser = new XmlParser(in);

    // Construct a DOM Document to parse XML.
    Document document = new Document ();
    document.parse(parser);
    in.close();

    // Make an OutputStream on which WbxmlWriter can write.
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    AbstractXmlWriter writer = new WbxmlWriter(out);
    document.write(writer);
    writer.close();

    // Get WBXML from this stream.
    xmlData = out.toString().getBytes();
    out.close();

    }//try
    catch (Exception e) { e.printStackTrace(); }
    return xmlData;
    }//getWBXMLStream

    public static void main(String[] args)
    {
    byte[] buff = new byte[8272];
    // boolean cont = true;
    int emp,t=0;
    FileInputStream infile = null;

    try
    {
    infile = new FileInputStream("F:\\temp\\example.wbxml");
    }
    catch (FileNotFoundException e)
    {
    System.err.println("没有找到文件");
    System.exit(1);
    }

    try
    {

    while ((emp=infile.read())!=-1)
    {
    buff[t++]=(byte)emp;
    System.out.print((char)emp);
    }
    System.out.println("t="+t);


    } catch (Exception e)
    {
    e.printStackTrace();
    }


    try
    {
    infile.close();
    } catch (IOException e)
    {
    System.err.println("there is some wrong in file");
    System.exit(1);
    }

    Test2 b=new Test2();
    byte [] a = new byte[8272];
    a= b.getXMLStream(buff);
    System.out.println("the output");
    for(int i=0;i<a.length;i++)
    System.out.print((char)a[i]);
    // System.out.write(a,0,3272);
    }


    }

  2. #2
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: i want to convert wbxml into xml ,what wrong in this codes

    Take a look at this thread, it's about the same topic: http://discussion.forum.nokia.com/fo...d.php?t=109110

    Hope this article will help you somehow, Compressing XML For Faster Wireless Networking: http://java.sun.com/developer/J2METe...0325.html#tip2
    Last edited by axs; 2007-06-04 at 12:09.

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

    Re: i want to convert wbxml into xml ,what wrong in this codes

    please tell what error you are getting.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    4,105
    chinadeng, have you gone through the kXML documentation and examples already? How is this related to Java Mobile (J2ME MIDlets)?

    The short answer to your question: You have to know the tag and attribute mapping tables of your WBXML and then configure kXML to use those while prcessing the WBXML (parsing or converting). WBXML alone cannot be converted to XML. You have to know these mappings which were used when creating the WBXML.

  5. #5
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Re: i want to convert wbxml into xml ,what wrong in this codes

    Quote Originally Posted by traud
    chinadeng, have you gone through the kXML documentation and examples already? How is this related to Java Mobile (J2ME MIDlets)?

    The short answer to your question: You have to know the tag and attribute mapping tables of your WBXML and then configure kXML to use those while prcessing the WBXML (parsing or converting). WBXML alone cannot be converted to XML. You have to know these mappings which were used when creating the WBXML.
    thank you your information

  6. #6
    Registered User
    Join Date
    Jun 2007
    Posts
    12

    Re: i want to convert wbxml into xml ,what wrong in this codes

    Quote Originally Posted by ramyashashe
    please tell what error you are getting.
    when i have run the programme ,the output is also the same as the example.wbxml.the programme can not convert the wbxml into xml.

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

    Re: i want to convert wbxml into xml ,what wrong in this codes

    hi,

    please check with this code, i am able to convert wbxml successfully to xml in j2me midp program. you are using same in java program is it?

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

    Document document = new Document ();
    document.parse(parser);
    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 (Exception e) {e.printStackTrace();}
    return wbxmlData;
    }

  8. #8
    Registered User
    Join Date
    Jul 2008
    Posts
    1

    Re: i want to convert wbxml into xml ,what wrong in this codes

    Hi;
    I also use kxml; but; it seem converting from xml to wbxml not correctly. Because once i provisoin through smpp; the message arrived; but; said; not compartible.

    can any one help on this?

    K.Tech

Similar Threads

  1. Parsing wbxml file to xml file using kxml parser
    By ramyashashe in forum Mobile Java General
    Replies: 18
    Last Post: 2010-05-17, 15:56
  2. Replies: 4
    Last Post: 2008-03-06, 10:38
  3. xml sax parse get the attribute wrong!
    By isarc in forum Symbian
    Replies: 4
    Last Post: 2007-05-18, 02:53
  4. xml or wbxml rights specification?
    By htc in forum OMA DM/DS/CP
    Replies: 0
    Last Post: 2006-09-06, 08:02
  5. Replies: 0
    Last Post: 2002-09-30, 15:54

Posting Permissions

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