简体   繁体   English

使用XML格式化通信中的数据是否是一个好主意?

[英]Is it a good idea to use XML for formatting data in communication?

I was going to use XML for communicating some data betwwen my server and the client, then I saw few articles saying using XML at any occation may not be the best idea. 我打算使用XML在服务器和客户端之间传递一些数据,然后我看到很少的文章说在任何场合使用XML都不是最好的主意。 The reason given was using XML would increase the size of my message which is quite true, specially for me where nost of my messages are very short ones. 给出的原因是使用XML会增加我的消息的大小,这的确是正确的,特别是对于我的消息中很少的消息。

Is it a good idea to send several information segements seperated by a new line? 发送以换行分隔的多个信息段是一个好主意吗? (maximum diffenernt types of data that one message may have is 3 or 4) Or what are the alternative methods that I should look in to. (一条消息可能具有的最大不同数据类型为3或4)或者我应该寻找的替代方法是什么。

I have diffenrent types of messages. 我有不同类型的消息。 Ex: one message may contain username and password and the next message may have current location and speed. 例如:一条消息可能包含用户名和密码,下一条消息可能具有当前位置和速度。 I'll be using apache server and php. 我将使用apache服务器和php。

Serializing data in an XML format can certainly have the negative side effect of bloating it a little ( the angle bracket tax ), but the incredible extensibility of XML greatly outweighs that consequence, IMO. 以XML格式序列化数据无疑会给数据带来一点消极的负面影响( 尖括号税 ),但是IMO令人难以置信的XML可扩展性大大超过了这种后果。 Also, you can serialize XML in a binary format which greatly cuts down on size, and in most cases the additional bloat would be negligible. 另外,您可以将XML序列化为二进制格式,从而大大减小了大小,并且在大多数情况下,额外的膨胀可以忽略不计。

Separating your information segments by newlines could be problematic if your information segments might ever need to include newlines. 如果您的信息段可能需要包含换行符,则用换行符分隔信息段可能会出现问题。

JSON is a much lighter weight alternative to XML, and lots of software that supports XML often supports JSON as an alternative. JSON是XML的轻巧替代品,许多支持XML的软件通常都支持JSON作为替代品。 It's pretty easy to use. 它很容易使用。 Since your messages are short, it sounds like they would benefit from using JSON over XML. 由于您的消息很短,因此听起来可以通过在XML上使用JSON受益。

http://json.org/ http://json.org/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM