gpt4 book ai didi

android - 如何在 Android 应用程序中使用 xmlserializer 创建 xml

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:51:39 26 4
gpt4 key购买 nike

您好,我正在制作一个预订应用程序,我需要在创建 xml 后将 xml 发送到服务器。

如何使用 xmlserializer 创建 xml 并在创建后将其发送到服务器?

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
&currencyCode=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>

最佳答案

您需要为字符串输出创建编写器。

@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();
}

输出字符串是这样的:

   <?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<file>
<something ID="000001">
<name>
CO
</name>
</something>
</file>

但是我不知道怎么发送。也许,你可以把这个字符串转换成字节。

关于android - 如何在 Android 应用程序中使用 xmlserializer 创建 xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9869507/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com