<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>blog.humaneguitarist.org &#187; XQuery</title>
	<atom:link href="http://blog.humaneguitarist.org/tag/xquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.humaneguitarist.org</link>
	<description>discoveries in digital audio, music notation, and information encoding</description>
	<lastBuildDate>Tue, 07 Feb 2012 03:33:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>LS-598 #2: XQuery problems and solutions</title>
		<link>http://blog.humaneguitarist.org/2010/02/04/ls-598-2-xquery-problems-and-solutions/</link>
		<comments>http://blog.humaneguitarist.org/2010/02/04/ls-598-2-xquery-problems-and-solutions/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 13:29:47 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[music notation]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[BaseX]]></category>
		<category><![CDATA[MODS]]></category>
		<category><![CDATA[MXMLiszt]]></category>
		<category><![CDATA[XQuery]]></category>
		<category><![CDATA[XQuery processor]]></category>

		<guid isPermaLink="false">http://blog.humaneguitarist.org/?p=777</guid>
		<description><![CDATA[Just a quick morning post today &#8230; The last 10 days or so I&#39;ve been struggling with some major problems that arose in trying to implement effective XQuer-ies on my web demo. Dublin Core doesn&#39;t allow me to differentiate creator &#34;types&#34;, so I was limited to searching across the DC:creator element for all creators, be [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick morning post today &#8230;</p>
<p>The last 10 days or so I&#39;ve been struggling with some major problems that arose in trying to implement effective XQuer-ies on my web demo.</p>
<ol>
<li>Dublin Core doesn&#39;t allow me to differentiate creator &quot;types&quot;, so I was limited to searching across the DC:creator element for all creators, be they Composer, Lyricist, or Arranger. MusicXML does differentiate these types, so essentially Dublin Core was making me &quot;dumb down&quot; some information. I want people to be able to search creator specifically by their role: Composer, Lyricist, or Arranger.</li>
<li>I needed a way to iterate an XQuery over all the MusicXML documents and I&nbsp;needed it to be relatively fast. A demo is a demo, but impatience is impatience and I just can&#39;t accept slow query processing.</li>
<li>The XQuery processor I&nbsp;was using didn&#39;t support some XQuery functions that would allow a searcher to type in &quot;Bach&quot; and retrieve documents for which the creator was &quot;J.S Bach&quot;, &quot;Johann Sebastian Bach&quot;, &quot;Bach, J.S&quot;, &quot;P.D.Q Bach&quot;, etc. This really was limiting the search/query coolness factor and I&nbsp;wasn&#39;t at all happy about it.</li>
</ol>
<p>Here are my solutions (details to follow in a few days or so):</p>
<ol>
<li>Ditch Dublin Core and switch to MODS, which does allow me to specify the role of a creator. Last week, I made a MusicXML to MODS XSL transformation for descriptive metadata and it&#39;s working well.</li>
<li>Steal an idea from <a href="http://ismir2008.ismir.net/papers/ISMIR2008_217.pdf">Using XQuery on MusicXML Databases for Musicological Analysis</a> so that rather than iterate one query (say for the number of notes in a piece) across multiple MusicXML&nbsp;docs, I just concatenated all the MusicXML&nbsp;documents. The original files are left alone, but a &quot;super&quot; MusicXML file gets created so that one can just query that one file, hence no need for lengthy iteration. I&#39;m not sure how those fellows did it, but I just automated it via PHP&nbsp;using the following format:</li>
</ol>
<p style="margin-left: 80px;"><code>&nbsp;&lt;hyperMXML&gt;</code></p>
<p style="margin-left: 120px;"><code>&lt;hypoMXML file=&quot;foo1.xml&quot;&gt;</code></p>
<p style="margin-left: 160px;"><code><span style="color: rgb(255, 0, 0);">1st MusicXML document</span></code></p>
<p style="margin-left: 120px;"><code>&lt;/hypoMXML&gt;</code></p>
<p style="margin-left: 120px;"><code>&lt;hypoMXML file=&quot;foo2.xml&quot;&gt;</code></p>
<p style="margin-left: 160px;"><code><span style="color: rgb(255, 0, 0);">2nd MusicXML document</span></code></p>
<p style="margin-left: 120px;"><code>&lt;/hypoMXML&gt;</code></p>
<p style="margin-left: 80px;"><code>&lt;/hyperMXML&gt;</code></p>
<ol start="3">
<li>Switch XQuery processors! I&#39;ll go into the ones that didn&#39;t support the function I&nbsp;needed another time, but I&nbsp;will say that <a href="http://www.inf.uni-konstanz.de/dbis/basex/index.php">BaseX</a> did the trick. Below is the query that searches for creators with &quot;Bach&quot; somewhere in MusicXML&#39;s &lt;creator&gt;&nbsp;element. For the deliverable demo, I won&#39;t be querying these big MusicXML documents for simple descriptive metadata like Creator, that&#39;s what the MODS is for. But this is just an example. The &quot;ftcontains&quot; syntax is what allows for retrieval of values where &quot;Bach&quot;&nbsp;is somewhere within the element, but isn&#39;t necessarily equivalent to the entire element value.</li>
</ol>
<p style="margin-left: 80px;"><code>for $i in doc(&quot;../temp/concat/concatMXML.xml&quot;)/hyperMXML/hypoMXML/score-partwise<br />
	where $i/identification/creator <span style="color: rgb(255, 0, 0);">ftcontains &quot;Bach&quot;</span><br />
	return ($i/work/work-title)</code></p>
<hr />
<p><span style="font-size: smaller;">This blog post is part of a semester-long investigation into digital encoding of symbolic music representation (SMR), its context in libraries, web-based delivery, preservation and metadata, and search and retrieval technologies.</span><span style="font-size: smaller;"><br />
	</span></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.humaneguitarist.org/2010/02/04/ls-598-2-xquery-problems-and-solutions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>running XQuery online</title>
		<link>http://blog.humaneguitarist.org/2009/11/08/running-xquery-online/</link>
		<comments>http://blog.humaneguitarist.org/2009/11/08/running-xquery-online/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 01:26:54 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[scripts]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Saxon]]></category>
		<category><![CDATA[XQuery]]></category>

		<guid isPermaLink="false">http://blog.humaneguitarist.org/?p=450</guid>
		<description><![CDATA[A while ago, I&#160;posted about my first experience with XQuery and how I&#39;d used the .NET version of the Saxon processor on my local Windows machine. Obviously, I&#160;want to extend that experience to running XQueries online. So far, I&#160;know this can easily be done with a native XML database server like eXist. That is to [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago, I&nbsp;posted about my <a href="http://blog.humaneguitarist.org/?p=152">first experience with XQuery</a> and how I&#39;d used the .NET version of the <a href="http://saxon.sourceforge.net/">Saxon</a> processor on my local Windows machine.</p>
<p>Obviously, I&nbsp;want to extend that experience to running XQueries online. So far, I&nbsp;know this can easily be done with a native XML database server like <a href="http://exist-db.org/">eXist</a>. That is to say, when I installed eXist on my local machine and made it go live: bam! &#8211; instant XML server with built-in XQuery functionality, accessible from anywhere.</p>
<p>Another way is to use one of the more popular web-scripting languages to execute XQuery syntax. I nearly killed myself this weekend trying to install the <a href="http://www.ibm.com/developerworks/opensource/library/x-zorba/index.html">Zorba PHP binding for XQuery</a> (i.e. run XQuery natively from within a PHP&nbsp;script). I just couldn&#39;t get all the dependencies successfully installed on my virtual install of <a href="http://www.ubuntu.com/getubuntu/download-netbook?info=EXLINK">Ubuntu Netbook Remix</a> (BTW: I&nbsp;use Sun&#39;s <a href="http://www.virtualbox.org/">VirtualBox</a> for virtualization). Perhaps I&#39;ll be able to make it work another time.</p>
<p>Now, even though it makes all the sense in the world to stick with a native XML server like eXist if I want to make a large collection of searchable XML documents online (and I&nbsp;do), I&#39;m feeling non-sensical. What I&nbsp;decided to try was to run my computer as a more traditional server using the X-Apache-MySql-PHP model, specifically <a href="http://www.wampserver.com/en/">WampServer</a>.</p>
<p>From there, I&nbsp;placed my sample document, &quot;<a href="http://www.w3schools.com/XQuery/books.xml">books.xml</a>&quot; and my &quot;test.xquery&quot; file from last time:</p>
<pre class="brush:xml">&lt;ul&gt;
{
for $x in doc(&quot;books.xml&quot;)/bookstore/book/title
order by $x
return &lt;li&gt;{data($x)}&lt;/li&gt;
}
&lt;/ul&gt;</pre>
<p>in WAMP&#39;s &quot;www&quot; directory &#8211; i.e. the directory which is accessible from the browser, the place where one would put all their HTML files, etc. for the world to see.</p>
<p>Of course, I was still missing the actual XQuery processor at this point. What I tried is to put the relevant executables for Saxon in the &quot;www&quot; directory as well.</p>
<p>&#8230; Now, I&#39;m sure this is totally unsafe or something, but I was just testing and I only make my computer &quot;go live&quot;&nbsp;as a server for short periods of time.</p>
<p>Anyway, from there I&nbsp;used PHP to call the Saxon processor and to display the results in the browser. It actually worked!</p>
<p>Here&#39;s the code:</p>
<pre class="brush:php">&lt;?php
echo &quot;Hi. I&#39;m going to use XQuery to list the books alphabetically.&quot;;
exec(&quot;query.exe test.xquery !indent=yes&quot;, $results);
foreach ($results as $value)
    {
       echo &quot;$value&quot;;
    }
?&gt; </pre>
<p>You can see that the PHP &quot;exec&quot; command called the Saxon executable named &quot;query.exe&quot; and executes the &quot;test.xquery&quot; file.</p>
<p>It saves the results in a variable called &quot;results&quot; and then prints each value of the results in the browser.</p>
<p>For now, I&#39;m OK with this, but I need to eventually do the same thing with the Java version of Saxon, I&nbsp;suppose, if I&#39;m ever going to run this on a Linux server. It shouldn&#39;t present any new hurdles, but I need to try it to make sure, of course.</p>
<p>If anyone out there has any thoughts or recommendations on a more elegant method to achieve these results &#8211; and what the security risks of the approach I&#39;ve outlined presents (since I didn&#39;t use a CGI-bin), please speak up. I&#39;m all ears.</p>
<p><img alt=":)" src="http://blog.humaneguitarist.org/wp-content/plugins/fckeditor-for-wordpress-plugin/ckeditor/plugins/smiley/images/regular_smile.gif" title=":)" /></p>
<p>&#8230;</p>
<p><strong>Update, November, 2009:</strong> No problems with using the Java version of Saxon. I&nbsp;did place it in a &quot;bin&quot; directory on my local server so that the Java file wouldn&#39;t reside in the directory that users have direct access to.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.humaneguitarist.org/2009/11/08/running-xquery-online/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XQuery and MusicXML</title>
		<link>http://blog.humaneguitarist.org/2009/09/12/xquery-and-musicxml/</link>
		<comments>http://blog.humaneguitarist.org/2009/09/12/xquery-and-musicxml/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 00:11:47 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[music notation]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[ISMIR]]></category>
		<category><![CDATA[MusicXML]]></category>
		<category><![CDATA[XQuery]]></category>

		<guid isPermaLink="false">http://blog.humaneguitarist.org/?p=189</guid>
		<description><![CDATA[Earlier today,&#160; I posted about my first experience with XQuery. I&#39;d mentioned that I&#160;wanted to get my feet wet before I&#160;started trying to run queries on MusicXML&#160;documents. Well, I&#39;m an incredibly impatient person. I&#160;couldn&#39;t wait to take a couple of simple queries for a test run, especially after reading the following paper from the 2008 [...]]]></description>
			<content:encoded><![CDATA[<p style="margin-left: 40px"><span style="color: rgb(0, 0, 0);">Earlier today,&nbsp; I posted about</span><span style="color: rgb(0, 0, 0);"> <a href="http://blog.humaneguitarist.org/?p=152">my first experience with XQuery</a>. I&#39;d mentioned that I&nbsp;wanted to get my feet wet before I&nbsp;started trying to run queries on MusicXML&nbsp;documents.</span></p>
<p>Well, I&#39;m an incredibly impatient person.</p>
<p>I&nbsp;couldn&#39;t wait to take a couple of simple queries for a test run, especially after reading the following paper from the 2008 International Conference on Music Information Retrieval hosted by <a href="http://www.ismir.net/">ISMIR</a>, the International Society for Music Information Retrieval: &nbsp;</p>
<p style="margin-left: 40px;"><em><a href="http://ismir2008.ismir.net/papers/ISMIR2008_217.pdf">Using XQuery on MusicXML Databases for Musicological Analysis</a></em><br />
	<em>Joachim Ganseman, Paul Scheunders and Wim D&rsquo;haes</em></p>
<p>Now, I&#39;ve known for a while the tests have been done using XQuery on MusicXML documents, but this paper was getting at something that&#39;s been on my mind for a long time now: the day we can have digital libraries of sheet music, not as image files, but as encoded documents, allowing musicians and the like to have the same online ability to query music in the way that users of prose and literary documents now take for granted.</p>
<p>Anyway, on to my first XQuery and MusicXML experience &#8230;</p>
<p>For testing, I used a very silly little ditty I&nbsp;wrote called &quot;MusicXML: I&nbsp;Heart Thee&quot;.</p>
<p>Here are its various manifestations:</p>
<ul>
<li>
<p><a href="http://blog.humaneguitarist.org/uploads/i_heart_thee.xml">MusicXML</a></p>
</li>
<li>
<p><a href="http://blog.humaneguitarist.org/uploads/i_heart_thee.jpg">JPEG</a></p>
</li>
<li>
<p><a href="http://blog.humaneguitarist.org/uploads/i_heart_thee.mp3">MP3</a></p>
</li>
</ul>
<p>The <a href="http://ismir2008.ismir.net/papers/ISMIR2008_217.pdf#page=3">first query demonstrated in the paper</a> (see page 3) is one to count the total notes in a digital library, in this case the <a href="http://www.wikifonia.org/">Wikifonia</a> collection of MusicXML docs.</p>
<p>I&nbsp;couldn&#39;t get it to work as written even after I&nbsp;adjusted the query to work on my test document. This is likely due to my own ignorance, but in the end it was a good thing because it forced me to write my own, simpler queries.</p>
<p>I&#39;m using the <a href="http://saxon.sourceforge.net/">Saxon</a> query processor as described in <a href="http://blog.humaneguitarist.org/?p=152">my earlier post</a>.</p>
<p>1. This query (in red) counts all the notes in my piece:</p>
<p style="margin-left: 40px;"><code><span style="color: rgb(255, 0, 0);">&lt;ul&gt;<br />
	{<br />
	for $i in doc(&quot;i_heart_thee.xml&quot;)/score-partwise<br />
	let $j :=count($i/part/measure/note)<br />
	return $j<br />
	}<br />
	&lt;/ul&gt;<br />
	</span></code></p>
<p><span style="background-color: rgb(255, 255, 0);"><em>A line-by-line translation:</em></span></p>
<ul>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Open an unordered list.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Open the query syntax with the &quot;{&quot; character.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Let there be a variable called &quot;i&quot; that will start at the root element, &lt;score-partwise&gt;, of the document &quot;i_heart_thee.xml&quot;.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Let there be a variable, &quot;j&quot;, that executes the Count function on &quot;i&quot; for the &lt;note&gt; element which is a child of &lt;measure&gt;&nbsp;and a grandchild of &lt;part&gt;.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Print the value of &quot;j&quot;.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Close the query syntax with the &quot;}&quot; character.</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Close the unordered list.</span></p>
</li>
</ul>
<p>2. This query (in red) counts all the notes in the vocal part (there are 3 parts altogether: voice, guitar, bass):</p>
<p style="margin-left: 40px;"><code><span style="color: rgb(255, 0, 0);">&lt;ul&gt;<br />
	{<br />
	for $i in doc(&quot;i_heart_thee.xml&quot;)/score-partwise<br />
	let $j :=count($i/part[@id=&#39;P1&#39;]/measure/note)<br />
	return $j<br />
	}<br />
	&lt;/ul&gt;</span></code><span style="color: rgb(255, 0, 0);"><br />
	</span></p>
<p><span style="background-color: rgb(255, 255, 0);"><em>A line-by-line translation:</em></span></p>
<ul>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Open an unordered list.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Open the query syntax with the &quot;{&quot; character.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Let there be a variable called &quot;i&quot; that will start at the root element, &lt;score-partwise&gt;, of the document &quot;i_heart_thee.xml&quot;.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Let there be a variable, &quot;j&quot;, that executes the Count function on &quot;i&quot; for the &lt;note&gt; element which is a child of &lt;measure&gt;&nbsp;and a grandchild of &lt;part&gt;, where the &quot;ID&quot; attribute of &lt;part&gt; is = to &quot;P1&quot;. This is the vocal part of the score.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Print the value of &quot;j&quot;.<br />
			</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Close the query syntax with the &quot;}&quot; character.</span></p>
</li>
<li>
<p><span style="background-color: rgb(255, 255, 255);">Close the unordered list.</span></p>
</li>
</ul>
<p><span style="background-color: rgb(255, 255, 255);">If you run the first query you get </span>the result &quot;137&quot; as in 137 notes, including rests &#8211; even the hidden rests in measures 1,5, and 9 that exist because both voices in the guitar part have rests, though it only displays as one rest each time on the <a href="http://blog.humaneguitarist.org/uploads/i_heart_thee.jpg">image version of the score</a>.</p>
<p>If you run the second query, you get 43 notes including rests and the tied notes.</p>
<p>I&#39;m sure there are ways to subtract rests and tied notes, but I&nbsp;have to start somewhere, right?</p>
<p><img alt=":)" src="http://blog.humaneguitarist.org/wp-content/plugins/fckeditor-for-wordpress-plugin/ckeditor/plugins/smiley/images/regular_smile.gif" title=":)" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.humaneguitarist.org/2009/09/12/xquery-and-musicxml/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
<enclosure url="http://blog.humaneguitarist.org/uploads/i_heart_thee.mp3" length="306443" type="audio/mpeg" />
<enclosure url="http://blog.humaneguitarist.org/uploads/i_heart_thee.mp3" length="306443" type="audio/mpeg" />
<enclosure url="http://blog.humaneguitarist.org/uploads/i_heart_thee.mp3" length="306443" type="audio/mpeg" />
<enclosure url="http://blog.humaneguitarist.org/uploads/i_heart_thee.mp3" length="306443" type="audio/mpeg" />
<enclosure url="http://blog.humaneguitarist.org/uploads/i_heart_thee.mp3" length="306443" type="audio/mpeg" />
		</item>
		<item>
		<title>on using XQuery for the first time</title>
		<link>http://blog.humaneguitarist.org/2009/09/12/on-using-xquery-for-the-first-time/</link>
		<comments>http://blog.humaneguitarist.org/2009/09/12/on-using-xquery-for-the-first-time/#comments</comments>
		<pubDate>Sat, 12 Sep 2009 16:26:13 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[XML]]></category>
		<category><![CDATA[Beanshell]]></category>
		<category><![CDATA[jEdit]]></category>
		<category><![CDATA[query]]></category>
		<category><![CDATA[XQuery]]></category>

		<guid isPermaLink="false">http://blog.humaneguitarist.org/?p=152</guid>
		<description><![CDATA[Obviously, I&#39;ve been playing around with XSLT lately. So naturally, the next logical step was to delve into XQuery, the XML query language de jure. Eventually I&#160;want to run queries on MusicXML&#160;documents, but I&#160;need to start small. While the W3Schools tutorial on XQuery is a great introduction, there&#39;s one little problem. It doesn&#39;t really tell [...]]]></description>
			<content:encoded><![CDATA[<p>Obviously, I&#39;ve been playing around with <a href="http://blog.humaneguitarist.org/?tag=xslt">XSLT</a> lately. So naturally, the next logical step was to delve into <span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span>, the XML query language <em>de jure</em>. Eventually I&nbsp;want to run queries on <a href="http://en.wikipedia.org/wiki/MusicXML">MusicXML</a>&nbsp;documents, but I&nbsp;need to start small.</p>
<p>While the <a href="http://www.w3schools.com/xquery/xquery_intro.asp">W3Schools tutorial on XQuery</a> is a great introduction, there&#39;s one little problem.</p>
<p>It doesn&#39;t really tell you how to implement <span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span>: i.e. how to actually run a query and retrieve results.</p>
<p>So after some random perusing and downloading, I&nbsp;- like the fool I&nbsp;am &#8211; was made aware by Dr. Michael Kay&#39;s &quot;<a href="http://www.stylusstudio.com/xquery_primer.html">Learn <span class="__mozilla-findbar-search" style="padding: 0pt; display: inline; font-size: inherit;">XQuery</span> in 10 Minutes: An <span class="__mozilla-findbar-search" style="padding: 0pt; display: inline; font-size: inherit;">XQuery</span> Tutorial</a>&quot;<span style="font-size: x-small;"><span style="font-family: Arial;">&nbsp; </span></span>that the Saxon XSLT&nbsp;processor I&nbsp;was already using for XSLT&nbsp;transformations already had an <span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span> engine built in.</p>
<p>That&#39;s to say that the <a href="https://sourceforge.net/projects/saxon/files/Saxon-B/9.1.0.7/saxonb9-1-0-7n.zip/download">.NET version of Saxon</a> has 2 command line executables:</p>
<ol>
<li><strong>Transform.exe</strong>, which I&#39;d already used for XSLT&nbsp;transformations</li>
<li><strong>Query.ex</strong><strong>e</strong>, which allows one to run <span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span> queries</li>
</ol>
<p>So much for paying attention to what I download &#8230;</p>
<p>From there, it was a simple matter to use <span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span> for the first time.</p>
<p>Here are the steps:</p>
<ol>
<li>I&nbsp;downloaded the <a href="http://www.w3schools.com/xquery/books.xml">books.xml</a> file provided by W3Schools and place it into the &quot;bin&quot;&nbsp;directory of Saxon on my drive. This is same directory where the 2 afformentioned executables reside.</li>
<li>Using the kick-tail text editor <a href="http://jedit.org/">jEdit</a>, I&nbsp;copy/pasted/saved this <a href="http://www.w3schools.com/xquery/xquery_flwor_html.asp">query example from the W3Schools</a> as &quot;test.<span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">xquery</span>&quot; (also saved in the &quot;bin&quot; directory):</li>
</ol>
<p style="margin-left: 80px;"><code><span style="color: rgb(255, 0, 0);">&lt;ul&gt;<br />
	{<br />
	for $x in doc(&quot;books.xml&quot;)/bookstore/book/title<br />
	order by $x<br />
	return &lt;li&gt;{<span class="marked">data(</span>$x<span class="marked">)</span>}&lt;/li&gt;<br />
	}<br />
	&lt;/ul&gt;</span></code><span style="color: rgb(255, 0, 0);"><br />
	</span></p>
<p style="margin-left: 80px;">This query simply lists all the titles from &quot;books.xml&quot; in alphabetical order.</p>
<ol start="3">
<li>Then using jEdit&#39;s command line plug-in called &quot;Console&quot;, I set Console to the Saxon &quot;bin&quot; directory where &quot;query.exe&quot;, &quot;books.xml&quot;, and &quot;test.<span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">xquery</span>&quot; reside. The easiest way to set the directory in Console is to type:</li>
</ol>
<p style="margin-left: 80px;"><code><span style="color: rgb(255, 0, 0);">cd &quot;C:\Documents and Settings\nitin\Desktop\saxon\bin&quot;</span></code><span style="color: rgb(255, 0, 0);"><br />
	</span></p>
<p style="margin-left: 80px;">Of course, you might extract Saxon elsewhere, but the important thing is to type <strong>cd</strong> <span style="color: rgb(128, 128, 128);">+</span> <strong>opening quotation mark</strong> <span style="color: rgb(128, 128, 128);">+</span> <strong>full path to Saxon&#39;s &quot;bin&quot; folder</strong> <span style="color: rgb(128, 128, 128);">+</span><strong> ending quotation mark</strong>.</p>
<ol start="4">
<li>Now I was in the correct folder and could run the <span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span> with the following command line syntax:</li>
</ol>
<p style="margin-left: 80px;"><code><span style="color: rgb(255, 0, 0);">query tes<span style="color: rgb(255, 0, 0);">t.<span class="__mozilla-findbar-search" style="padding: 0pt; display: inline; font-size: inherit;">xquery</span></span></span></code><span style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"><span class="__mozilla-findbar-search" style="padding: 0pt; display: inline; font-size: inherit;"><br />
	</span></span></span></p>
<p style="margin-left: 80px;">And my results look like this:</p>
<p style="text-align: center;"><img alt="" src="http://blog.humaneguitarist.org/uploads/xquery_jedit.jpg" /></p>
<p style="margin-left: 80px;">I know what you&#39;re thinking: no line breaks! Sure, the computer doesn&#39;t care, but this is really hard for humans to read!</p>
<p style="margin-left: 80px;">Yes, that&#39;s true. But I&nbsp;went ahead and pasted the following:</p>
<p style="margin-left: 120px;"><code><span style="color: rgb(255, 0, 0);">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;ul&gt;&lt;li&gt;Everyday Italian&lt;/li&gt;&lt;li&gt;Harry Potter&lt;/li&gt;&lt;li&gt;Learning XML&lt;/li&gt;&lt;li&gt;<span style="color: rgb(255, 0, 0);"><span class="__mozilla-findbar-search" style="padding: 0pt; display: inline; font-size: inherit;">XQuery</span> Ki</span>ck Start&lt;/li&gt;&lt;/ul&gt;</span></code><span style="color: rgb(255, 0, 0);"><br />
	</span></p>
<p style="margin-left: 80px;">into a new document in jEdit anyway.</p>
<p style="margin-left: 80px;">We&#39;re gonna take care of those line breaks now &#8230;</p>
<ol start="5">
<li>One of the many great things about jEdit is the ability to run <a href="http://www.beanshell.org/">Beanshell</a> commands, which despite my attempts to sound authoritative, I&nbsp;only learned about roughly 30 minutes ago. This means that a search and replace can be done in jEdit using simple Java syntax to fix that line break issue. The first step is identifying where to insert the line break. I needed it in between <strong>&gt;</strong> and <strong>&lt;</strong>. Specifically, I needed a line break between all the red and green colored brackets:</li>
</ol>
<p style="margin-left: 80px;"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?<span style="background-color: rgb(255, 0, 0);"><span style="color: rgb(0, 0, 0);">&gt;</span></span><span style="background-color: rgb(51, 153, 102);"><span style="color: rgb(0, 255, 0);">&lt;</span></span>ul<span style="background-color: rgb(255, 0, 0);"><span style="color: rgb(0, 0, 0);">&gt;</span></span><span style="background-color: rgb(51, 153, 102);"><span style="color: rgb(0, 255, 0);">&lt;</span></span>li&gt;Everyday Italian&lt;/li<span style="background-color: rgb(255, 0, 0);"><span style="color: rgb(0, 0, 0);">&gt;</span></span><span style="background-color: rgb(51, 153, 102);"><span style="color: rgb(0, 255, 0);">&lt;</span></span>li&gt;Harry Potter&lt;/li<span style="background-color: rgb(255, 0, 0);"><span style="color: rgb(0, 0, 0);">&gt;</span></span><span style="background-color: rgb(51, 153, 102);"><span style="color: rgb(0, 255, 0);">&lt;</span></span>li&gt;Learning XML&lt;/li<span style="background-color: rgb(255, 0, 0);"><span style="color: rgb(0, 0, 0);">&gt;</span></span><span style="background-color: rgb(51, 153, 102);"><span style="color: rgb(0, 255, 0);">&lt;</span></span>li&gt;<span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span> Kick Start&lt;/li<span style="background-color: rgb(255, 0, 0);"><span style="color: rgb(0, 0, 0);">&gt;</span></span><span style="background-color: rgb(51, 153, 102);"><span style="color: rgb(0, 255, 0);">&lt;</span></span>/ul&gt;</code></p>
<p style="margin-left: 80px;">&nbsp;So I just invoked the jEdit search/replace box and did the following:</p>
<p style="text-align: center;">
<input src="http://blog.humaneguitarist.org/uploads/xquery_jedit_replace.jpg" type="image" /></p>
<p style="text-align: left; margin-left: 80px;">This simply says:</p>
<p style="text-align: left; margin-left: 80px;"><em>Find</em> all instances of</p>
<p style="text-align: left; margin-left: 80px;"><strong>&gt;&lt; </strong></p>
<p style="text-align: left; margin-left: 80px;">and <strong><br />
	</strong></p>
<p style="text-align: left; margin-left: 80px;"><em>Replace</em> it with</p>
<p style="text-align: left; margin-left: 80px;"><strong>&gt;<br />
	</strong></p>
<p style="text-align: left; margin-left: 80px;"><strong>&lt;</strong></p>
<p style="text-align: left; margin-left: 80px;">- i.e. the text between the quotation marks. The <strong>n</strong> is, by the way, the line break syntax.</p>
<p style="text-align: left; margin-left: 80px;">When I hit &quot;Replace All&quot;, this was the result:</p>
<p style="text-align: left; margin-left: 120px;"><code><span style="color: rgb(255, 0, 0);">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br />
	&lt;ul&gt;<br />
	&lt;li&gt;Everyday Italian&lt;/li&gt;<br />
	&lt;li&gt;Harry Potter&lt;/li&gt;<br />
	&lt;li&gt;Learning XML&lt;/li&gt;<br />
	&lt;l<span style="color: rgb(255, 0, 0);">i&gt;<span class="__mozilla-findbar-search" style="padding: 0pt; display: inline; font-size: inherit;">XQuery</span> Kick Start&lt;</span>/li&gt;<br />
	&lt;/ul&gt;</span></code><span style="color: rgb(255, 0, 0);"><br />
	</span></p>
<p style="text-align: left; margin-left: 80px;">Problem solved.</p>
<ol start="6">
<li>Now I&nbsp;simply saved this document as &quot;test.html&quot; and opened it in a browser.</li>
</ol>
<p>Anyway, that&#39;s my very simple start to <span class="__mozilla-findbar-search" style="padding: 0pt; color: black; display: inline; font-size: inherit;">XQuery</span>, but I&#39;m feeling pretty good about it nonetheless.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.humaneguitarist.org/2009/09/12/on-using-xquery-for-the-first-time/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

