可能因?yàn)槲④洝BM這樣的商業(yè)公式和開源社區(qū)在數(shù)據(jù)表達(dá)方面的不謀而合,以及再加上W3C推波助瀾XML的相關(guān)技術(shù)總是和應(yīng)用結(jié)合得非常緊密。XML從產(chǎn)生就不乏優(yōu)秀的工具。在最近一個(gè)項(xiàng)目中,我們就使用了原生的XML存儲數(shù)據(jù)庫Berkely DBXML(BDB)。
其實(shí),DBXML使用了大量優(yōu)秀的開源工具來實(shí)現(xiàn),其中數(shù)據(jù)存儲使用Berkely DB,XML解析使用XercesC,XPath的實(shí)現(xiàn)使用Pathan(2.3以前),XQilla(2.3以后)。關(guān)于這幾個(gè)庫,我將官方網(wǎng)站的介紹摘錄如下:
- Xerces-C++ is a validating XML parser written in a portable subset of C++. Xerces-C++ makes it easy to give your application the ability to read and write XML data. A shared library is provided for parsing, generating, manipulating, and validating XML documents.
- Pathan is a open source library which allows developers using Xerces-C to parse and evaluate XPath expressions for XML node selection.
- XQilla is an XQuery and XPath 2 library and command line utility written in C++ , implemented on top of the Xerces-C. XQilla is originally based on an open source project called Pathan, that was hosted by Decisionsoft and implemented XPath 2. However, XQilla has been developed and improved considerably from the Pathan code base.
- Xalan is an XSLT processor for transforming XML documents into HTML, text, or other XML document types
在接下來的工作中,我們希望把存儲的XML表達(dá)出來。我們通過XSL來實(shí)現(xiàn)XML的表達(dá),有趣的是XSL
本身也是XML,又是一個(gè)有趣的遞歸。
把DBXML與XSL聯(lián)系起來。我們找到了一個(gè)DBXML API中函數(shù),他可以將XML Node 以Xerces DOMDocument 方式返回:
xercesc_2_6::DOMDocument *XmlDocument::getContentAsDOM() const;
我們要還要引入一個(gè)庫Xalan C++。Xalan C++可以將生成的結(jié)果存儲在一個(gè)Xerces DOMDocument中;可以使用
TransformToXercesDOM將XercesDOM作為轉(zhuǎn)換的源。
在XML開源軟件中還有一支,那就是來自MIT的xmlsoft.org。其中最著名的libxml2和基于libxml2的libxslt,均應(yīng)用到gnome上。這些都是C的API包,在此基礎(chǔ)上有C++綁定,PHP綁定,perl綁定等等。debian下的php-mod-xml就源自這里。
openoffice的OpenDocument基于XML,xml.openoffice.org上也有一些實(shí)現(xiàn),同樣值得關(guān)注。