开发者

How to parse a regular String to an XML file

What I'm trying to do is to parse an object into a String, and then , parse it into an XML so any other language can translate it.

Figure out this object:

public class DatosPac 
{
private String nombre;
private String apellidos;
private Stri开发者_Go百科ng dni;
public String getNombre() {
    return nombre;
}
public void setNombre(String nombre) {
    this.nombre = nombre;
}
public String getApellidos() {
    return apellidos;
}
public void setApellidos(String apellidos) {
    this.apellidos = apellidos;
}
public String getDni() {
    return dni;
}
public void setDni(String dni) {
    this.dni = dni;
}   
}

What I want to do is, parse it into a common XML between Android and .Net so both languages can translate the same object. The way to communicate both languages will be using Web Services, so the Web Service will receive a String, transalte it into the object and then use the information. Bidirectionally. I mean, Android will be able to receive an object parsed from .Net, and .Net will be able to receive the same object from Android. To be able to do this, I think I need to convert them into the same XML, but I don't know how to do it in Android.

Thanks in advance.


There are several XML serializing and de-serializing libraries available for Android. And I am sure the same's the case with .NET.

You set up your objects as POJOs and with a few annotations, you can serialize/deserialize in a few lines of code. In the Android world, I personally prefer Simple, but there are various other libraries available.

A more compact, (and more efficient, in terms of parsing) data representation format is JSON. There are multiple libraries available for parsing and constructing JSON too. My preferred one for Android is Gson.


EDIT: I believe I was a bit too quick! I didn't notice the android tag and assumed a .net context. Still, one bit stands: You probably want to serialize, not to "parse" the object, into XML.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜