可能因為微軟、IBM這樣的商業公式和開源社區在數據表達方面的不謀而合,以及再加上W3C推波助瀾XML的相關技術總是和應用結合得非常緊密。XML從產生就不乏優秀的工具。在最近一個項目中,我們就使用了原生的XML存儲數據庫Berkely DBXML(BDB)。
其實,DBXML使用了大量優秀的開源工具來實現,其中數據存儲使用Berkely DB,XML解析使用XercesC,XPath的實現使用Pathan(2.3以前),XQilla(2.3以后)。關于這幾個庫,我將官方網站的介紹摘錄如下:
- 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表達出來。我們通過XSL來實現XML的表達,有趣的是XSL
本身也是XML,又是一個有趣的遞歸。
把DBXML與XSL聯系起來。我們找到了一個DBXML API中函數,他可以將XML Node 以Xerces DOMDocument 方式返回:
xercesc_2_6::DOMDocument *XmlDocument::getContentAsDOM() const;
我們要還要引入一個庫Xalan C++。Xalan C++可以將生成的結果存儲在一個Xerces DOMDocument中;可以使用
TransformToXercesDOM將XercesDOM作為轉換的源。
在XML開源軟件中還有一支,那就是來自MIT的xmlsoft.org。其中最著名的libxml2和基于libxml2的libxslt,均應用到gnome上。這些都是C的API包,在此基礎上有C++綁定,PHP綁定,perl綁定等等。debian下的php-mod-xml就源自這里。
openoffice的OpenDocument基于XML,xml.openoffice.org上也有一些實現,同樣值得關注。