Use XQuery with Flare Files

XQuery is another XML query language. XQuery uses XPath expressions, so XPath 2.0 is included with XQuery 1.0. The World Wide Web Consortium (W3C) published XQuery 1.0: An XML Query Language as recommendation in 2007 and edited to XQuery 1.0: An XML Query Language (Second Edition) in 2010. The W3C recommendation is posted at:

To use XQuery, you need an XQuery implementation. W3C lists implementations known to W3C at:

To demonstrate XQuery, we will use a freely available technology. As of writing this, Microsoft SQL Server 2012 Express has an implementation of XQuery. You can download the database, tools, or both. But don’t feel limited to using the SQL Server implementation to learn about XQuery.

In the XPath post, we queried a Flare TOC for the Link attribute nodes for every TocEntry element. But we retrieved the attribute node. We could not filter for just the attribute value. With XQuery, we can accomplish that. Here is an XQuery code executed with Transact-SQL to create hyperlinks for every TOC entry in a generated Flare TOC in the Data folder of an HTML5 output.


'<?xml version="1.0" encoding="utf-8"?>
    Title="Test Topic 1"
    Link="/Content/TestTopic1.htm" />
    Title="Test Topic 2"
    Link="/Content/TestTopic2.htm" />
    Title="Test Topic 3"
    Link="/Content/TestTopic3.htm" />

SELECT @FLTOC.query('for $TocEntry in (//TocEntry) 
			return <a href="{$TocEntry/@Link}">{string($TocEntry/@Title)}</a>') AS Links

The output is:

<a href="/Content/TestTopic1.htm">Test Topic 1</a>
<a href="/Content/TestTopic2.htm">Test Topic 2</a>
<a href="/Content/TestTopic3.htm">Test Topic 3</a>

But there is a pitfall here. Not every TocEntry element has a link attribute. So be careful. If you are working with a FLTOC file in a project, there is another pitfall. Not every link is to a topic file. So be even more careful there.

Leave a comment

Your email address will not be published.

HTML tags are not allowed.

241,673 Spambots Blocked by Simple Comments