Hi am making a booking app and i need to send an xml to the server after creating the xml.
How to create the xml using xmlserializer
and send it to a server after creating it?
http://api.ean.com/ean-services/rs/hotel/v3/list?
minorRev=[current minorRev #]
&cid=55505
&apiKey=[xxx-yourOwnKey-xxx]
&customerUserAgent=[xxx]&customerIpAddress=[xxx]
&locale=en_US
¤cyCode=USD
&xml=
<HotelListRequest>
<city>Seattle</city>
<stateProvinceCode>WA</stateProvinceCode>
<countryCode>US</countryCode>
<arrivalDate>08/01/2012</arrivalDate>
<departureDate>08/03/2012</departureDate>
<RoomGroup>
<Room>
<numberOfAdults>2</numberOfAdults>
</Room>
</RoomGroup>
<numberOfResults>1</numberOfResults>
<supplierCacheTolerance>MED_ENHANCED</supplierCacheTolerance>
</HotelListRequest>
XML tags define the data and used to store and organize data. It's easily scalable and simple to develop. In Android, the XML is used to implement UI-related data, and it's a lightweight markup language that doesn't make layout heavy. XML only contains tags, while implementing they need to be just invoked.
XML stands for eXtensible Markup Language, which is a way of describing data using a text-based document. Because XML is extensible and very flexible, it's used for many different things, including defining the UI layout of Android apps.
XML namespaces provide a way to qualify the names of XML elements and attributes in XML documents. A qualified name consists of a prefix and a local name, separated by a colon. The prefix functions only as a placeholder; it is mapped to a URI that specifies a namespace.
The XmlSerializer creates C# (. cs) files and compiles them into . dll files in the directory named by the TEMP environment variable; serialization occurs with those DLLs. These serialization assemblies can be generated in advance and signed by using the SGen.exe tool.
You need to create writer for string output.
@SuppressWarnings("null")
public static String CreateXMLString() throws IllegalArgumentException, IllegalStateException, IOException
{
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter writer = new StringWriter();
xmlSerializer.setOutput(writer);
//Start Document
xmlSerializer.startDocument("UTF-8", true);
xmlSerializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
//Open Tag <file>
xmlSerializer.startTag("", "file");
xmlSerializer.startTag("", "something");
xmlSerializer.attribute("", "ID", "000001");
xmlSerializer.startTag("", "name");
xmlSerializer.text("CO");
xmlSerializer.endTag("", "name");
xmlSerializer.endTag("", "something");
//end tag <file>
xmlSerializer.endTag("", "file");
xmlSerializer.endDocument();
return writer.toString();
}
And the output string is like this:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<file>
<something ID="000001">
<name>
CO
</name>
</something>
</file>
But i don't know how to send it.Maybe, you can convert this string into bytes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With