数据报包转xml
我正在尝试使用 XMLPullParser 解析 Soap ProbeMatch 消息。我通过 UDP 多播收到此消息。我使用以下代码来接收它。
byte[] buf = new byte[1900];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
mSocket.receive(packet);
// Damn ugly....
String data = new String(packet.getData())
如果我将 byte[] 转换为 String ,解析器不会吃掉它......有没有更优雅的方法来做到这一点?
当我打印 xml(作为字符串)时,我在字符串末尾得到未使用的字节:
</s12:Envelope>À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?
Im trying to parse a Soap ProbeMatch message with XMLPullParser. I receive this via UDP Multicast. I use the following code to receive it.
byte[] buf = new byte[1900];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
mSocket.receive(packet);
// Damn ugly....
String data = new String(packet.getData())
If i convert the byte[] to String the Parser doesnt eat it... Are there any more elegant ways to do this?
When i print the xml (as String), i get the unused bytes at the end of the String:
</s12:Envelope>À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?À?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我认为您需要按如下方式构造字符串:
至于是否有更好的方法。 AIUI 并不是真的,尽管可能有第三方 API 可以使填充/清空数据报变得更容易一些,因为所有字节打包都非常繁琐。
First off, I think you'll want to construct the String as follows:
As to there being a better way. AIUI not really, though there might be a third party API out there that makes filling/emptying the datagrams a bit easier, as all the byte packing is very fiddly.