<?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>@TheKeyboard &#187; xml-db</title>
	<atom:link href="http://www.littlehart.net/atthekeyboard/tag/xml-db/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.littlehart.net/atthekeyboard</link>
	<description>Facebook should&#039;ve be written in unicornSchemaLang, because everyone *knows* that PHP is no good for anything, right?</description>
	<lastBuildDate>Wed, 08 Sep 2010 01:58:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>More XML-DB Fun!</title>
		<link>http://www.littlehart.net/atthekeyboard/2007/11/30/more-xml-db-fun/</link>
		<comments>http://www.littlehart.net/atthekeyboard/2007/11/30/more-xml-db-fun/#comments</comments>
		<pubDate>Fri, 30 Nov 2007 18:51:34 +0000</pubDate>
		<dc:creator>Chris Hartjes</dc:creator>
				<category><![CDATA[Chris' Brain]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[exist]]></category>
		<category><![CDATA[xml-db]]></category>

		<guid isPermaLink="false">http://www.littlehart.net/atthekeyboard/2007/11/30/more-xml-db-fun/</guid>
		<description><![CDATA[We had a nice corporate retreat last week, an opportunity for all the members of XMLTeam to get together (and in some cases meet face-to-face for the first time) and discuss what's going on and figure out priorities over the next 12 months. If you're expecting some company secrets here, you'll be disappointed. One of [...]]]></description>
			<content:encoded><![CDATA[<p>
We had a nice corporate retreat last week, an opportunity for all the members of <a href="http://www.xmlteam.com">XMLTeam</a> to get together (and in some cases meet face-to-face for the first time) and discuss what's going on and figure out priorities over the next 12 months.  If you're expecting some company secrets here, you'll be disappointed. <img src='http://www.littlehart.net/atthekeyboard/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>
One of the things that got bandied around was whether or not we would continue using <a href="http://exist.sourceforge.net/">eXist</a> to store the XML documents that the application is using or go with a <a href="http://xtoss.org">database-driven solution</a>.  So, my partner on this project was tasked with figuring out how to update existing elements and attributes in this documents using eXist only.</p>
<p>
How can I put this?  Oh, I know:  traversing through large complicated XML documents to find one element that you need to update when the location could be in multiple places sucks!  Part of the reason for this may be my lack of XPath foo within PHP itself.  Besides, if eXist can handle this for us then why shouldn't we leverage this?  I liken it to being able to do an UPDATE statement in a database.  I don't do a SELECT where I grab the whole data set, then drill down through the data looking for one specific row.  You do an update with the proper key.  So, Paul (that's the co-worker) got to work figuring out for me while I refactored code to be ready for it.  He got one script working (yay!) so I hacked away and got a very simple one to work today.  Here it is (with some info changed to protect the status of the project:</p>
<div class="igBar"><span id="lcode-2"><a href="#" onclick="javascript:showPlainTxt('code-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-2">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">xquery version <span style="color:#CC0000;">"1.0"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare namespace sportsml=<span style="color:#CC0000;">"http://iptc.org/std/SportsML/2006-10-18/"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare namespace xts=<span style="color:#CC0000;">"http://www.xmlteam.com"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare namespace request=<span style="color:#CC0000;">"http://exist-db.org/xquery/request"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare namespace xmldb=<span style="color:#CC0000;">"http://exist-db.org/xquery/xmldb"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare namespace util=<span style="color:#CC0000;">"http://exist-db.org/xquery/util"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $league := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"league"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $league-name := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"league-name"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $team-key := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"team-key"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $colors := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"colors"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $location := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"location"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $name := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"name"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $nickname := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"nickname"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $abbreviation := request:get-parameter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">"abbreviation"</span>, <span style="color:#CC0000;">""</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">declare variable $league-doc := concat<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0000;">'/db/'</span>, $league, <span style="color:#CC0000;">'/dynamic-resource-file/'</span>, $league, <span style="color:#CC0000;">'.xml'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;dummy&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">if <span style="color:#006600; font-weight:bold;">&#40;</span>doc<span style="color:#006600; font-weight:bold;">&#40;</span>$league-doc<span style="color:#006600; font-weight:bold;">&#41;</span>/sports-content/statistic/group<span style="color:#FF9933; font-style:italic;">//team-metadata/@team-key=$team-key) then</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">for $team-metadata in doc<span style="color:#006600; font-weight:bold;">&#40;</span>$league-doc<span style="color:#006600; font-weight:bold;">&#41;</span>/sports-content/statistic/group<span style="color:#FF9933; font-style:italic;">//team-metadata[@team-key=$team-key]</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">return</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">update replace $team-metadata with</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;team -metadata&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute team-key <span style="color:#006600; font-weight:bold;">&#123;</span>$team-key<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute colors <span style="color:#006600; font-weight:bold;">&#123;</span>$colors<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;name&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute first <span style="color:#006600; font-weight:bold;">&#123;</span>$location<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute full <span style="color:#006600; font-weight:bold;">&#123;</span>$name<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute nickname <span style="color:#006600; font-weight:bold;">&#123;</span>$nickname<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute abbreviation <span style="color:#006600; font-weight:bold;">&#123;</span>$abbreviation<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/name&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;affiliation&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute membership-type <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#CC0000;">"league"</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute membership-key <span style="color:#006600; font-weight:bold;">&#123;</span>$league<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span>attribute membership-name <span style="color:#006600; font-weight:bold;">&#123;</span>$league-name<span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/affiliation&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/team&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">else</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">return</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/dummy&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>
So, this sits in eXist, which is running on top of <a href="tomcat.apache.org">Tomcat</a> and I send the data in by POST-ing to the script.  I was all set to start using cURL for this task but a quick search on the net found <a href="http://netevil.org/blog/2006/nov/http-post-from-php-without-curl">this blog posting by Wez Furlong</a> showing how to use streams to do what most people automatically associate with having to use cURL for.  I liked it so much I went and refactored some other code that was using cURL to use that stuff instead.  It's always nice to find out that something you've been doing can still be done, but with fewer lines of code and *still* be elegant.
</p>
<p>
I'm off to look closer at streams in PHP 5 and see what other hidden treats are there...</p>
]]></content:encoded>
			<wfw:commentRss>http://www.littlehart.net/atthekeyboard/2007/11/30/more-xml-db-fun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
