Convert XML string to a stream in android
I am currently working on an android application which requires sending a stream that contained the XML to the server. At the moment, I have an xml as a string in the client application and I want to convert the xml string into an input stream, so that the stream can be passed to the wcf service for processing. Does anyone know how to achieve this?
Here is the code I wrote in android(java) for converting the xml string into input stream, but i think there is some problem with it. Does anyone know what the problem is?
String xml = "<Tr rn="000000000000000" vr="T" sSpre="S" reg="P" dSpre="2000-01-01" dOdprt="2000-01-01" iban="SI00" eno="R" vir="B" maticnaPps="0000000000"><Imetnik davcna="00000000" matSub="0000000000" drz="705"><PopolnoIme>UNKNOWN</PopolnoIme><KratkoIme>UNKNOWN</KratkoIme><Naslov sifTipNaslova="00" sifObcina="000" sifPosta="0000" sifUlica="0000" sifNaselje="000" stHisna="000" sifHsmid="00000000"><Obcina>UNKNOWN</Obcina><Posta>UNKNOWN</Posta><Ulica>UNKNOWN</Ulica><Naselje>UNKNOWN</Naselje></Naslov></Imetnik></Tr>";
InputStream is= new ByteArrayInputStream(xml.getBytes("UTF-8"));
Thanks for any helps in advance.
I'm not sure what your concerns are. But your original string looks like this:
<Tr rn="000000000000000" vr="T" ...
with the escaped quotes in it.
When you convert that into your ByteArrayInputStream you get a byte array that looks like this:
0: <
1: T
2: r
3:
4: r
5: n
6: =
7: "
8: 0
9: 0
...
The escaped quotation marks are gone as part of the conversion. I'm not sure if this is disconcerting to you.
When I convert back from the input stream, I get a nicely formed string back, but it doesn't contain the "'s
.
上一篇: 用一个默认值初始化普通数组
下一篇: 在android中将XML字符串转换为流