Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Welcome to TinyXPath

TinyXPath is D port of (tiny)XPath implementation in c++. XPath is query language for querying XML. There is also an port of TinyXml (also originally written in c++), simple library for parsing xml tree.

Project Status

Development appears to have stalled after changeset 33 on 2006-07-01. Since then, a user has suggested some patches in the forum:

Bugs

* (WILL BE CORRECTED) There is an major bug while parsing ::following, or ::preceding xpath query (parse error)
* (FEATURE) Another bug is in TinyXml port, if an error occurs while parsing xml, the error output doesn't contain valid file & line number.

Changelog

v.0.9.1

  • Fixed some major bugs

v.0.9

  • Initial Release

Release

- version 0.9.1 (fixed some bugs)
- version 0.9 (with above stated bugs)

Documentation

Why use XPath?

'Why use XPath? It's just another language I must learn!' XPath is very useful for parsing XML, the old-school (DOM recursive) parsing is very slow and needs a lot to hardcode, but using XPath simplifies things a lot. Plus, there is no useable XML parser for D at this moment, so TinyXPath includes also D port of TinyXML.

Official documentation

XPath language is an official w3c standard.

TinyXPath documentation

Official API documentation for C++ implementation. D implementation uses the same API, with no differences

Example of use

For exhausting example, see test.d. Illustration:

RSS (xml):

<rss version="2.0">
	<channel>
		<link>http://www.dsource.org/projects/tinyxpath/</link>
		<description>a tiny C++ XPath processor (tinyxpath project)</description>
		<generator>Notepad</generator>
		<item>
			<title>TinyXPath 0.9 released</title>
			<description>The initial release is out!</description>
			<author>the.yossarian@gmail.com Yossarian (original autor: Yves Berquin)</author>
			<link>http://sourceforge.net/forum/forum.php?forum_id=345812</link>
			<guid isPermaLink="true">http://sourceforge.net/forum/forum.php?forum_id=345812</guid>
			<pubDate>Sun, 18 Jan 2004 13:33:55 GMT</pubDate>
		</item> 
	</channel>
</rss>

D testing code

import xpath_static;
import xpath_processor;
import std.stdio;

int main()
{
 auto TiXmlDocument XDp_doc = new TiXmlDocument;
 XDp_doc.LoadFile("rss.xml");
 writefln("Expression: %s, result: %d", "count(/rss/channel/item)", i_xpath_int (XNp_root.RootElement, "count(/rss/channel/item)")); // returns number of items
 writefln("Expression: %s, result: %s", "/rss/channel/item[1]/pubDate/text()", S_xpath_string(XNp_root.RootElement, "/rss/channel/item[1]/pubDate/text()")); // returns publication date of first element
 return 0;
}

Excepted result:

Expression: count(/rss/channel/item), result: 1
Expression: /rss/channel/item[1]/pubDate/text(), result: Sun, 18 Jan 2004 13:33:55 GMT

Bug reports

Please use TinyXPath's forum.