How to modify values of a XML in J2ME?

泪湿孤枕 提交于 2019-11-28 11:25:56

问题


Suppose there is a XML in my J2ME application :

<?xml version="1.0"?>
<appli>
   <client id=134447>
      <name>Patrick</name>
      <email>patrick@mail.com</email>
   </client>
</appli>

How to modify from J2ME the node value "patrick@mail.com" for example ?


回答1:


For you XML sample you could write a class like:


    class Client {
        String id;
        String name;
        String email;
    }

And unmarshall your XML to it. I have shared a way of doing this with SAX from JSR 172 at http://smallandadaptive.blogspot.com.br/2010/11/xml-data-binding.html.

To marshall your class back to XML you can create a method like:


    String toXML() {
        StringBuffer sb = new StringBuffer();

        sb.append("<client id=\"").append(id).append("\">");
        sb.append("<name>").append(name).append("</name>");
        sb.append("<email>").append(email).append("</email>");
        sb.append("</client>");

        return sb.toString();
    }



来源:https://stackoverflow.com/questions/10041347/how-to-modify-values-of-a-xml-in-j2me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!