以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML基础 』  (http://bbs.xml.org.cn/list.asp?boardid=1)
----  请大家讨论XML文档中能不能嵌入二进制数据  (http://bbs.xml.org.cn/dispbbs.asp?boardid=1&rootid=&id=41416)


--  作者:slimzhao
--  发布时间:12/20/2006 9:52:00 AM

--  请大家讨论XML文档中能不能嵌入二进制数据
我已经在网上搜过, 有下面的办法:
1. 用base64 编码, 本质上还是在XML中存放文本数据
2. 在 CDATA中, 我怀疑这是一个广为流传的误区, 因为w3c 的规范中说CDATA 中放的仍是字符数据, 而且不能含有]]> 这个结束符号.
3. 指向外部entity, 这个不讨论
=============================
2.7 CDATA Sections

[Definition: CDATA sections may occur anywhere character data may occur; they are used to escape blocks of text containing characters which would otherwise be recognized as markup. CDATA sections begin with the string "<![CDATA[" and end with the string "]]>":]
CDATA Sections
[18]    CDSect    ::=    CDStart CData CDEnd
[19]    CDStart    ::=    '<![CDATA['
[20]    CData    ::=    (Char* - (Char* ']]>' Char*))
[21]    CDEnd    ::=    ']]>'

Within a CDATA section, only the CDEnd string is recognized as markup, so that left angle brackets and ampersands may occur in their literal form; they need not (and cannot) be escaped using "&lt;" and "&amp;". CDATA sections cannot nest.

An example of a CDATA section, in which "<greeting>" and "</greeting>" are recognized as character data, not markup:

<![CDATA[<greeting>Hello, world!</greeting>]]>
=============================
所以 CDATA方法是不究竟不彻底的, 不能真正地用来放二进制数据. 即使不考虑]]>这个结束符, 用下面的办法生成从0到255的所有字节值放在 CDATA段中不能被 xerces 所解析
for i in $(seq 0 1 255); do printf "%02x" $i; done | xxd -r -ps > 0_255.bin

我的目标是设计一种XML格式, 需要携带大量的任意二进制数据, 要求格式紧凑高效, 欢迎指教


--  作者:Qr
--  发布时间:12/20/2006 10:23:00 AM

--  
XML 实质上就是一个文本文件。
http://bbs.w3china.org/dispbbs.asp?boardID=1&ID=6256
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
6,414.063ms