Samuh
Samuh

Reputation: 36484

Better way to create XMLs at Runtime

I am working on an Android application that is required to connect to a REST WebService. There are a number of requests that the application needs to make and the request format is XML. What I have done presently is create a Request template per XML request using StringBuilder class and substitute a placeholder String for different values that need to be passed at Runtime.

For instance:

StringBuilder TEMPLATE = new StringBuilder("<GetStatusReq><item>@itemid@</item></GetStatusReq>");

The request XMLs contain about 20-30 nodes with some of them containing attributes. So you can imagine the complexity.

Is this the correct way to handle such a case? Or Should I be using XMLSerializer(need a link to good tutorial)?

What is the ideal way to handle such cases?

Please help.

Thanks.

Upvotes: 1

Views: 222

Answers (1)

Teja Kantamneni
Teja Kantamneni

Reputation: 17482

I would suggest using xstream for marshaling and unmarshaling the xml. It is light weight and has small memory footprint.

Upvotes: 2

Related Questions