<?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>Jabbering Giraffe &#187; xml</title>
	<atom:link href="http://happygiraffe.net/blog/tag/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://happygiraffe.net/blog</link>
	<description></description>
	<lastBuildDate>Wed, 19 Oct 2011 10:40:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>To XHTML or not to XHTML?</title>
		<link>http://happygiraffe.net/blog/2009/07/15/to-xhtml-or-not-to-xhtml/</link>
		<comments>http://happygiraffe.net/blog/2009/07/15/to-xhtml-or-not-to-xhtml/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 19:47:57 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1556</guid>
		<description><![CDATA[Today, we had a conversation about HTML 4 vs XHTML 1.0. For me, the matter was neatly settled they very first time I saw an XML system produce XHTML like this: &#60;p&#62;An article with an &#60;em/&#62; empty emphasis tag.&#60;/p&#62; Perfectly &#8230; <a href="http://happygiraffe.net/blog/2009/07/15/to-xhtml-or-not-to-xhtml/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today, we had a conversation about HTML 4 vs XHTML 1.0.  For me, the matter was neatly settled they very first time I saw an XML system produce XHTML like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>An article with an <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;em</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span> empty emphasis tag.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Perfectly legal XML, perfectly legal XHTML.  But — if you serve up this <strong>X</strong>HTML as <code>text/html</code> (which 99.99% of the world does), then you end up with this:</p>
<p><img src="http://happygiraffe.net/blog/wp-content/uploads/2009/07/empty-em.png" alt="Empty tags considered harmful" border="0" width="462" height="105" /></p>
<p>Why?  Because it&#8217;s parsed as HTML.  And the browser sees the start of an em tag, but no close.</p>
<p>And now I make sure that all our sites emit HTML 4.  It&#8217;s a lot simpler.</p>
<p>This isn&#8217;t to say I don&#8217;t use XHTML.  It&#8217;s a fine medium for further processing (e.g. applying XSLT).  But it&#8217;s not right for serving up to browsers verbatim.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2009/07/15/to-xhtml-or-not-to-xhtml/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>SAX EntityResolver</title>
		<link>http://happygiraffe.net/blog/2008/08/28/sax-entityresolver/</link>
		<comments>http://happygiraffe.net/blog/2008/08/28/sax-entityresolver/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 08:03:36 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/blog/?p=1337</guid>
		<description><![CDATA[I was trying to resolve entities (&#38;weirdChar;) in an XML file. Easy enough, use a validating parser. But here&#8217;s the tricky bit: get the entity definitions from the classpath. This should still be easy, as SAX provides an EntityResolver. Unfortunately, &#8230; <a href="http://happygiraffe.net/blog/2008/08/28/sax-entityresolver/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was trying to resolve entities (<code>&amp;weirdChar;</code>) in an XML file.  Easy enough, use a validating parser.  But here&#8217;s the tricky bit: get the entity definitions from the <a href="http://en.wikipedia.org/wiki/Classpath_(Java)">classpath</a>.  This <em>should</em> still be easy, as SAX provides an <a href="http://java.sun.com/javase/6/docs/api/org/xml/sax/EntityResolver.html">EntityResolver</a>.</p>
<p>Unfortunately, the interactions between <a href="http://en.wikipedia.org/wiki/JAXP">JAXP</a> and <a href="http://en.wikipedia.org/wiki/SAX">SAX</a> make life complicated.  I found that you have to ignore the <a href="http://java.sun.com/javase/6/docs/api/javax/xml/parsers/SAXParser.html">SAXParser</a> (from JAXP) and instead focus on the <a href="http://java.sun.com/javase/6/docs/api/org/xml/sax/XMLReader.html">XMLReader</a> interface (part of plain old SAX).</p>
<p>This is what I came up with.  First, a small driver.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> parseIt<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    SAXParserFactory spf <span style="color: #339933;">=</span> SAXParserFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    spf.<span style="color: #006633;">setValidating</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    XMLReader reader <span style="color: #339933;">=</span> spf.<span style="color: #006633;">newSAXParser</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getXMLReader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    reader.<span style="color: #006633;">setEntityResolver</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MyResolver<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">// Look for test.xml on the classpath.</span>
    <span style="color: #003399;">InputStream</span> testXmlStream <span style="color: #339933;">=</span> App.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getClassLoader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;test.xml&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    reader.<span style="color: #006633;">parse</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> InputSource<span style="color: #009900;">&#40;</span>testXmlStream<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>That references the EntityResolver implementation I wrote:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #000000; font-weight: bold;">class</span> MyResolver <span style="color: #000000; font-weight: bold;">implements</span> EntityResolver2 <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> InputSource resolveEntity<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> name, <span style="color: #003399;">String</span> publicId, <span style="color: #003399;">String</span> baseURI, <span style="color: #003399;">String</span> systemId<span style="color: #009900;">&#41;</span>
      <span style="color: #000000; font-weight: bold;">throws</span> SAXException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #003399;">InputStream</span> stream <span style="color: #339933;">=</span> getClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getClassLoader</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getResourceAsStream</span><span style="color: #009900;">&#40;</span>systemId<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> InputSource<span style="color: #009900;">&#40;</span>stream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Actually, I had to use <a href="http://java.sun.com/javase/6/docs/api/org/xml/sax/ext/EntityResolver2.html">EntityResolver2</a> for reasons I don&#8217;t entirely understand.</p>
<p>On top of this, I found that I had to include xerces 2.8 explicitly as a dependency.  The version bundled with Java 1.5 is Xerces 2.6.2, which has a bug: It passes the entity resolver an absolutized systemId.  Which makes it very difficult to resolver further.  What a pain in the arse.</p>
<p>But it does now work, and I can successfully resolve entities off the classpath.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/08/28/sax-entityresolver/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing XML in Java</title>
		<link>http://happygiraffe.net/blog/2008/08/05/writing-xml-in-java/</link>
		<comments>http://happygiraffe.net/blog/2008/08/05/writing-xml-in-java/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 12:34:42 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2008/08/05/writing-xml-in-java/</guid>
		<description><![CDATA[Last night, I was looking at generating SAMS XML from Java objects. It made me realise two things: Java sucks badly at creating XML (by default). I should really be looking at XML Binding. I&#8217;m interested in point 1. I&#8217;ve &#8230; <a href="http://happygiraffe.net/blog/2008/08/05/writing-xml-in-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Last night, I was looking at generating <span class="caps">SAMS XML</span> from Java objects.  It made me realise two things:</p>
<ol>
<li>Java sucks badly at creating <span class="caps">XML</span> (by default).</li>
<li>I should really be looking at <a href="http://en.wikipedia.org/wiki/XML_data_binding#Java"><span class="caps">XML</span> Binding</a>.</li>
</ol>
<p>I&#8217;m interested in point 1.  I&#8217;ve done it before, trying to write <span class="caps">XML</span> using <a href="http://en.wikipedia.org/wiki/Document_Object_Model"><span class="caps">DOM</span></a> (as there doesn&#8217;t appear to be a builtin <span class="caps">SAX</span> writer).  This is what I ended up with.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractXmlBuilder <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> addXlinkHref<span style="color: #009900;">&#40;</span><span style="color: #003399;">Element</span> e, URI href<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        e.<span style="color: #006633;">setAttributeNS</span><span style="color: #009900;">&#40;</span>Constants.<span style="color: #006633;">XLINK_NS</span>, <span style="color: #0000ff;">&quot;x:href&quot;</span>, href.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">// See http://www.cafeconleche.org/books/xmljava/chapters/ch09s09.html</span>
    <span style="color: #666666; font-style: italic;">// (JAXP Serialisation) for details on why all this palaver is necessary.</span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">String</span> domToString<span style="color: #009900;">&#40;</span><span style="color: #003399;">Document</span> doc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            TransformerFactory factory <span style="color: #339933;">=</span> TransformerFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Transformer trans <span style="color: #339933;">=</span> factory.<span style="color: #006633;">newTransformer</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            trans.<span style="color: #006633;">setOutputProperty</span><span style="color: #009900;">&#40;</span>OutputKeys.<span style="color: #006633;">OMIT_XML_DECLARATION</span>, <span style="color: #0000ff;">&quot;yes&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            DOMSource source <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DOMSource<span style="color: #009900;">&#40;</span>doc<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #003399;">StringWriter</span> writer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">StringWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            StreamResult streamResult <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> StreamResult<span style="color: #009900;">&#40;</span>writer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            trans.<span style="color: #006633;">transform</span><span style="color: #009900;">&#40;</span>source, streamResult<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> writer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransformerConfigurationException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransformerFactoryConfigurationError e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>TransformerException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Document</span> newDocument<span style="color: #009900;">&#40;</span><span style="color: #003399;">String</span> namespaceURI, <span style="color: #003399;">String</span> qualifiedName<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
            DocumentBuilderFactory dbf <span style="color: #339933;">=</span> DocumentBuilderFactory.<span style="color: #006633;">newInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            dbf.<span style="color: #006633;">setNamespaceAware</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            DocumentBuilder docBuilder <span style="color: #339933;">=</span> dbf.<span style="color: #006633;">newDocumentBuilder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            DOMImplementation impl <span style="color: #339933;">=</span> docBuilder.<span style="color: #006633;">getDOMImplementation</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000000; font-weight: bold;">return</span> impl.<span style="color: #006633;">createDocument</span><span style="color: #009900;">&#40;</span>namespaceURI, qualifiedName, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ParserConfigurationException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span>e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Document</span> newDocument<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Document</span> doc <span style="color: #339933;">=</span> newDocument<span style="color: #009900;">&#40;</span>Constants.<span style="color: #006633;">MY_NS</span>, <span style="color: #0000ff;">&quot;doc&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #003399;">Element</span> root <span style="color: #339933;">=</span> doc.<span style="color: #006633;">getDocumentElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        root.<span style="color: #006633;">setPrefix</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;my&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #666666; font-style: italic;">// Set up the usual namespaces.</span>
        root.<span style="color: #006633;">setAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;xmlns:x&quot;</span>, Constants.<span style="color: #006633;">XLINK_NS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> doc<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #003399;">Element</span> myElem<span style="color: #009900;">&#40;</span><span style="color: #003399;">Document</span> doc, <span style="color: #003399;">String</span> name<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">return</span> doc.<span style="color: #006633;">createElementNS</span><span style="color: #009900;">&#40;</span>Constants.<span style="color: #006633;">MY_NS</span>, name<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is intended to be subclassed to be useful, but even in the subclasses, it still relies on dozens of helper methods.  e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #003399;">Element</span> getAccIdElem<span style="color: #009900;">&#40;</span>SessionCreateRequest s, <span style="color: #003399;">Document</span> doc<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #003399;">Element</span> accId <span style="color: #339933;">=</span> myElem<span style="color: #009900;">&#40;</span>doc, <span style="color: #0000ff;">&quot;acc_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        addXlinkHref<span style="color: #009900;">&#40;</span>accId, s.<span style="color: #006633;">getAccountId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> accId<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>This is incredibly verbose, but I don&#8217;t think we can do better with just the <span class="caps">JDK</span>.  What are the other options?  I&#8217;ve been looking at <a href="http://xom.nu/"><span class="caps">XOM</span></a>.  This appears to have a nice <span class="caps">API</span> for writing <span class="caps">XML</span>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">    <span style="color: #003399;">Element</span> root <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Element</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;root&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    root.<span style="color: #006633;">appendChild</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello World!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">Document</span> doc <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Document</span><span style="color: #009900;">&#40;</span>root<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>doc.<span style="color: #006633;">toXML</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is much, much simpler.  We&#8217;re still building a up a <span class="caps">DOM</span>-like structure, but it&#8217;s simpler to use.</p>
<p>But <span class="caps">XOM</span> is still a fairly large dependency.  This doesn&#8217;t particularly matter for what I&#8217;m doing.  But there are alternatives.  Whilst looking for libraries, I also stumbled across <a href="http://www.osjava.org/xmlwriter/">xmlwriter</a>.  This is much lower-level:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  <span style="color: #003399;">Writer</span> writer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> java.<span style="color: #006633;">io</span>.<span style="color: #003399;">StringWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  XmlWriter xw <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> SimpleXmlWriter<span style="color: #009900;">&#40;</span>writer<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeXmlVersion</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeComment</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Example of XmlWriter running&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeEntity</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;person&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span>, <span style="color: #0000ff;">&quot;fred&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;age&quot;</span>, <span style="color: #0000ff;">&quot;12&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeEntity</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;phone&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;4254343&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">endEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeComment</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Examples of empty tags&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeEntity</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;friends&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeEmptyEntity</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;bob&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeEmptyEntity</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jim&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">endEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">writeEntityWithText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;foo&quot;</span>,<span style="color: #0000ff;">&quot;This is an example.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">endEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  xw.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #003399;">System</span>.<span style="color: #006633;">err</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span>writer.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This is closer to <a href="http://www.tbray.org/ongoing/When/200x/2004/02/20/GenxStatus">genx</a>, a C library that I like very much.  It&#8217;s quite weird that &#8220;element&#8221; and &#8220;entity&#8221; appear to be confused, though.  Plus there doesn&#8217;t appear to be any way to generate <a href="http://www.w3.org/TR/xml-c14n">canonical <span class="caps">XML</span></a>.</p>
<p>For now, I think I&#8217;ll stick with <span class="caps">XOM</span>, but it&#8217;s good to know that there are alternatives to the heavyweight <span class="caps">JDK</span> options.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2008/08/05/writing-xml-in-java/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dynamic JUnit</title>
		<link>http://happygiraffe.net/blog/2007/04/27/dynamic-junit/</link>
		<comments>http://happygiraffe.net/blog/2007/04/27/dynamic-junit/#comments</comments>
		<pubDate>Fri, 27 Apr 2007 06:24:09 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2007/04/27/dynamic-junit/</guid>
		<description><![CDATA[Recently, I wanted to do something slightly unusual with JUnit. I&#8217;m working on a cocoon project, so there are squillions of little XML files floating around. These need to be all well-formed. So I want a test that parses each &#8230; <a href="http://happygiraffe.net/blog/2007/04/27/dynamic-junit/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Recently, I wanted to do something slightly unusual with JUnit.  I&#8217;m working on a cocoon project, so there are squillions of little <span class="caps">XML</span> files floating around.  These need to be all well-formed.  So I want a test that parses each one.  Then, <a href="http://cruisecontrol.sourceforge.net/">CruiseControl</a> can let us know when they get broken.</p>
<p>First, I gave the task to a colleague.  He came up with something that checked each file, and returned a list of the bad ones.  It then asserted that the <code>nonWellFormed</code> list had a zero length.  Which is great and all, but didn&#8217;t tell you which file was broken, nor why.</p>
<p>What I really wanted to do was have a single test per file, so it could display the errors correctly.  This seemed like an easy thing to do&#8230;  Until I tried it.  This is what I eventually arrived at:</p>
<pre>
  class WellFormedTest extends TestCase {
    public static Test suite() {
        final TestSuite suite = new TestSuite(WellFormedTest.class.getCanonicalName());
        // Stupid bloody Java regexes have to match from the beginning of the
        // string.
        Pattern p = Pattern.compile(".*\\.(xml|xslt|xconf|xmap)$");
        FindFiles ff = new FindFiles(p) {
            protected void processFile(final File file) {
                suite.addTest(new WellFormedTest(file));
            }
        };
        ff.search("web");
        return suite;
    }

    private File file;

    public WellFormedTest(File file) {
      super("Well-Formed? " + file.toString());
      this.file = file;
    }

    protected void runTest() throws Throwable {
      XmlValidator validator = new XmlValidator();
      String result = validator.isWellFormed(file);
      assertEquals(file.toString(), null, result);
    }
  }
</pre>
<ul>
<li>FindFiles is a utility class to walk a directory tree.  Tell me again why Java doesn&#8217;t have something this basic in it&#8217;s vast class libraries?</li>
<li>You have to call <code>super("blah")</code> in your constructor to name each test sensibly.</li>
<li>But if you do this, you have to override <code>runTest()</code> in order for things to actually work.  The usual mechanism for determining which tests to run doesn&#8217;t work if you supply a custom name.  This took forever to work out and required delving into the JUnit source.  Halleluljah for Open Source.
<ul>
<li>As part of prodding around in the debugger, I noticed that JUnit creates a new TestCase object for each test in the class.  So it&#8217;s OK to just do one thing in <code>runTest()</code>, as that&#8217;s all that&#8217;s going to happen anyway.</li>
</ul>
</li>
<li>XmlValidator is another custom helper class.  It just parses the file and returns a String containing the error (or null).</li>
<li>Yes, this is JUnit 3.8.  I know I need to migrate to JUnit 4.  That&#8217;s a battle for another day, dependent on upgrading ant first.</li>
</ul>
<p>Originally, I tried to get the test done inside a nested anonymous subclass of TestCase, but there&#8217;s no constructor there, so that doesn&#8217;t work too well.  Plus it bumps the ugliness of the source another level.</p>
<p>The end result works quite well and provides a useful example for doing dynamic tests with JUnit.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2007/04/27/dynamic-junit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cocoon</title>
		<link>http://happygiraffe.net/blog/2007/04/15/cocoon/</link>
		<comments>http://happygiraffe.net/blog/2007/04/15/cocoon/#comments</comments>
		<pubDate>Sun, 15 Apr 2007 22:31:16 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cocoon]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2007/04/15/cocoon/</guid>
		<description><![CDATA[Surprising as it may seem if you only read this blog, I don&#8217;t do much Perl or Ruby or Rails. I try to in my spare time, but it&#8217;s not what I&#8217;m doing at $WORK. That&#8217;s mostly concerned with pushing &#8230; <a href="http://happygiraffe.net/blog/2007/04/15/cocoon/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Surprising as it may seem if you only read this blog, I don&#8217;t do much Perl or Ruby or Rails.  I try to in my spare time, but it&#8217;s not what I&#8217;m doing at <code>$WORK</code>.  That&#8217;s mostly concerned with pushing around <span class="caps">XML</span> using Java.  Right now, I&#8217;m trying to learn <a href="http://cocoon.apache.org/">Cocoon</a>.</p>
<p>Cocoon is a framework (in much the same way that Rails is), but it&#8217;s oriented to pushing around <span class="caps">XML</span>[1].  The basics of cocoon are pretty simple.  There&#8217;s a &#8220;pipeline&#8221; for processing <span class="caps">XML</span>:</p>
<ul>
<li>A <em>generator</em> produces <span class="caps">XML</span>.  Usually, this is just reading a file.  At <code>$WORK</code>, it&#8217;s pulled from an <span class="caps">XML</span> database.</li>
<li>Zero or more <em>transformers</em> munge the <span class="caps">XML</span> in various ways.  Normally, this is <span class="caps">XSLT</span>.</li>
<li>Finally, it gets output through a <em>serializer</em>.  Mostly this will be <span class="caps">HTML</span>.</li>
</ul>
<p>There&#8217;s a little bit more to it, but that&#8217;s the basics.  And for serving up <span class="caps">XML</span> directly, in a read-only fashion it actually works really well.</p>
<p>The problems start when you want to get a little bit more interactive.  It seems that Cocoon has evolved a number of different approaches over the years, but the current favourite appears to be <a href="http://cocoon.apache.org/2.1/userdocs/flow/index.html">FlowScript</a>.</p>
<p>FlowScript is server-side JavaScript<sup><a href="#fn2">2</a></sup>.  When an <span class="caps">URL</span> is matched, a little bit of JavaScript gets run in order to determine what to do.  It can interact with Java objects and when it&#8217;s figured out what to do, run the appropriate pipeline, passing in parameters.  It&#8217;s effectively an <span class="caps">MVC</span> architecture, with the controller being JavaScript.</p>
<p>But what&#8217;s <em>really</em> neat about FlowScript is captured in a single call:</p>
<pre>
  function calculator()
  {
    var a, b, operator;

    cocoon.sendPageAndWait("getA.html");
    a = cocoon.request.get("a");

    cocoon.sendPageAndWait("getB.html");
    b = cocoon.request.get("b");

    cocoon.sendPage("result.html", {result: a + b});
  }
</pre>
<p><code>cocoon.sendPageAndWait()</code> uses a <a href="http://en.wikipedia.org/wiki/Continuation">continuation</a> to effectively pause the execution of the JavaScript, return to the browser and when the user submits the form again, the FlowScript will carry on executing after the call to <code>cocoon.sendPageAndWait()</code>.  Neat stuff.</p>
<p>Continuations are currently the hot thing because of <a href="http://www.seaside.st/">seaside</a>, a web framework for smalltalk.  But cocoon&#8217;s had them for a couple of years.</p>
<p>Building on FlowScript is a framework for form handling called <a href="http://cocoon.apache.org/2.1/userdocs/basics/index.html">CForms</a>.  The idea is that you define a model for your form, which then gets rendered into <span class="caps">HTML</span>.  I&#8217;m playing with this for a very complex form at the moment, and I&#8217;m not totally sold on the concept.  Plus the generated result is some pretty yucky markup.</p>
<p>In fact, there are quite a few things about cocoon that make me feel uncomfortable about it.</p>
<ul>
<li>It&#8217;s <em>huge</em>.  The download is 50Mb, and you get a lot in that.  The problem is two fold: firstly, you don&#8217;t need most of it most of the time.  Secondly, figuring out what you do actually need is bloody hard work.  e.g.  I still haven&#8217;t figured out what the hell the &#8220;apples&#8221; block is.</li>
<li>It gets complicated very quickly when you step outside the core competencies.  If you follow the CForms link, you&#8217;ll see what I mean.</li>
<li>Debugging is hard.  Partially, this is down to the nature of <span class="caps">XML</span> (and in particular <a href="http://www.w3.org/TR/REC-xml-names/"><span class="caps">XML</span> Namespaces</a>), but in general, you&#8217;re not working with Java, so it&#8217;s difficult to get the level of debugging one would be used to.  The error messages that do appear are somewhat vague.</li>
<li>Cocoon 2.2.  The current version, 2.1, is a bit old now.  I&#8217;ve been trying to find out more about cocoon 2.2 by poking around in the dev list.  It appears that cocoon has been converted to a <a href="http://maven.apache.org/">maven</a> project and switched to use <a href="http://www.springframework.org/">Spring</a> internally.  It&#8217;s Maven that I have a big issue with.  It basically means that there isn&#8217;t a download any more.  Instead, you just tell maven &#8220;make me a new cocoon 2.2 project&#8221; and it goes and downloads it.  From somewhere you may or may not trust.  That may or may not be compiled correctly.  Oh, and they&#8217;ve completely reorganised how you integrate with a standard servlet container.  And the docs aren&#8217;t updated yet.  All this, combined with the fact that when maven blew up when I tried it means I&#8217;m not happy with the future direction of the project.  Maybe with better docs, I&#8217;d be happier.  We&#8217;ll see&#8212;the proper release should be &#8220;soon&#8221;.</li>
</ul>
<p>Overall, I&#8217;m left with a mixed feeling about Cocoon.  For it&#8217;s core purpose, I like it.  Beyond that, I&#8217;m less certain.  The trouble is that pretty much any web site you create these days falls into that &#8220;beyond&#8221; bit quite quickly&#8212;even the large, static ones like we create at $WORK.  I kind of wish that it had some competition, but there doesn&#8217;t appear to be a lot out there that comes close to dealing with <span class="caps">XML</span> as well as Cocoon.</p>
<p>I&#8217;m going on a training course in a couple of weeks.  We&#8217;ll have to see if that reassures me any that Cocoon is the correct choice.</p>
<p id="fn1"><sup>1</sup>  <span class="caps">XML</span> oftens gets a lot of stick, but for its intended purpose (documents, as opposed to data), it&#8217;s a pretty reasonable solution.</p>
<p id="fn2"><sup>2</sup>  Which appears to be coming back into fashion, what with things like <a href="https://phobos.dev.java.net/">Project Phobos</a> and <a href="http://www.zimki.com/">Zimki</a>.  Although it does go back a long way to the Netscape web server&#8212;see <a href="http://en.wikipedia.org/wiki/Server-side_JavaScript">Server Side JavaScript</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2007/04/15/cocoon/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The year of XQuery?</title>
		<link>http://happygiraffe.net/blog/2007/01/07/the-year-of-xquery/</link>
		<comments>http://happygiraffe.net/blog/2007/01/07/the-year-of-xquery/#comments</comments>
		<pubDate>Sun, 07 Jan 2007 22:18:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xquery]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2007/01/07/the-year-of-xquery/</guid>
		<description><![CDATA[Apparently, it&#8217;s the year of xquery. I&#8217;ve just started a large project at $WORK, of which XQuery is a fundamental piece. And I have to say I&#8217;m not so sure. From what I&#8217;ve seen so far, there are good and &#8230; <a href="http://happygiraffe.net/blog/2007/01/07/the-year-of-xquery/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Apparently, it&#8217;s the <a href="http://www.xml.com/pub/a/2007/01/03/the-xquery-chimera-takes-center-stage.html">year</a> <a href="http://www.oreillynet.com/xml/blog/2006/12/through_a_glass_darkly_predict.html">of</a> <a href="http://www-128.ibm.com/developerworks/library/x-xml2006conf.html">xquery</a>.  I&#8217;ve just started a large project at $WORK, of which <a href="http://en.wikipedia.org/wiki/XQuery">XQuery</a> is a fundamental piece.  And I have to say I&#8217;m not so sure.</p>
<p>From what I&#8217;ve seen so far, there are good and bad bits to XQuery.  The good bits are that it&#8217;s really flexible and very easy to pull apart large quantities of <span class="caps">XML</span> documents in ways in which it&#8217;s much, much harder with <span class="caps">XSLT</span>.  I like the way <span class="caps">XML</span> fragments are treated as just another datatype, like <a href="http://en.wikipedia.org/wiki/E4X"><span class="caps">E4X</span></a> but done right.  I also like the way that it&#8217;s built on XPath, as XPath rocks.</p>
<p>Sadly, there are quite a few more bad bits.</p>
<ul>
<li>The development environment leaves a lot to be desired (an eclipse plugin would be nice, as would vim<sup><a href="#fn1">1</a></sup> or emacs<sup><a href="#fn2">2</a></sup> syntax highlighting).</li>
<li>XQuery itself is really verbose.  There appears to be a lot of syntax, and the grammar is on the large side.  This means that it&#8217;s really hard to pick up large bodies of other peoples code.  Coincidentally like the stuff I&#8217;ve been dumped with.</li>
<li>The spirit of the language is more like <span class="caps">SQL</span> than any procedural language.  Yet it presents a veneer of procedurality, which fools you into thinking you can get away with things like &#8220;just throw an extra statement in&#8221;.  It&#8217;s not that simple.  Your XQuery code is returning a list of items<sup><a href="#fn3">3</a></sup>, so instead you have to insert your extra code as a previous item in the list.  Essentially, this means you <em>must</em> end your extra code with a comma, instead of the expected semicolon or nothing.  This continues to bite me.</li>
<li>It&#8217;s still not a standard.  &#8220;Nearly there now&#8221;, apparently.  It&#8217;s beginning to sound like Perl 6&#8230;</li>
<li>Namespaces continue to cause me much wailing and gnashing of teeth.  In XQuery, there is a tendency to use quite a few of them as well.  In fairness, this is more of an <span class="caps">XML</span> problem than an XQuery problem, but it&#8217;s really irritating to still be tripped up by having xpath not match because you&#8217;re not looking at a namespace by accident.</li>
<li>The type system is a pain.  XQuery may or may not be strongly typed, depending upon the code you&#8217;re using, the implementation, or the phase of the moon.  It has had a tendency to get in the way, in all the stuff I&#8217;ve seen so far.</li>
<li>For all its verbosity, the language itself is quite limited.  I&#8217;ve been needing to use a lot of implementation-specific extensions in the work I&#8217;ve been doing.  Particularly for things like updates.</li>
<li>Oh, and whoever chose fucking <em>smileys</em> as the comment syntax needs to be shot.  Now.</li>
</ul>
<p>Having said all that, I think XQuery is still useful in the area I&#8217;m working in (large corpus&#8217; of <span class="caps">XML</span> documents).  Despite my rash of indignation, it&#8217;s proved a lot easier to deal with than our previous technology (flat files plus manually created indexes in an <span class="caps">RDBMS</span> plus Lucene for searching).  It has a future.  I just hope it develops quicker than it has so far.</p>
<p id="fn1"><sup>1</sup>  That doesn&#8217;t suck, anyway, unlike <a href="http://jmvanel.free.fr/vim/xquery.vim">xquery.vim</a>.</p>
<p id="fn2"><sup>2</sup>  I haven&#8217;t tried <a href="http://www.emacswiki.org/cgi-bin/wiki/xquery-mode.el">xquery-mode.el</a> yet.</p>
<p id="fn3"><sup>3</sup>  Except where it isn&#8217;t, e.g. defining functions.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2007/01/07/the-year-of-xquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML::Genx Plans</title>
		<link>http://happygiraffe.net/blog/2006/06/07/xml-genx-plans/</link>
		<comments>http://happygiraffe.net/blog/2006/06/07/xml-genx-plans/#comments</comments>
		<pubDate>Wed, 07 Jun 2006 05:45:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cpan]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2006/06/07/xml-genx-plans/</guid>
		<description><![CDATA[I was talking to Mark Fowler yesterday and XML::Genx came up. He had a couple of good points: It&#8217;s not absolutely clear in the documentation that any valid Perl string will work correctly (be it UTF-8 encoded or not). I &#8230; <a href="http://happygiraffe.net/blog/2006/06/07/xml-genx-plans/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was talking to <a href="http://2shortplanks.com/">Mark Fowler</a> yesterday and <a href="http://search.cpan.org/dist/XML-Genx"><span class="caps">XML</span>::Genx</a> came up.  He had a couple of good points:</p>
<ul>
<li>It&#8217;s not <em>absolutely</em> clear in the documentation that any valid Perl string will work correctly (be it <span class="caps">UTF</span>-8 encoded or not).  I need to double check the tests for this and amend the docs.</li>
<li>The <span class="caps">API</span> is still fairly horrible.  It mirrors the C api almost exactly, but this feels very odd as a Perl programmer.  I need to have a think about what would be better.  Ideally, I&#8217;d like something more like ruby&#8217;s <a href="http://builder.rubyforge.org/">builder</a>.  In fact, I actually wrote something similar  to that before (<a href="http://search.cpan.org/dist/XML-SAX-Builder/lib/XML/SAX/Builder.pm"><span class="caps">XML</span>::SAX::Builder</a>), but that uses <span class="caps">SAX</span>, which is too slow in Perl.</li>
</ul>
<p>I really appreciate the feedback.  Apart from <a href="http://plasmasturm.org/">Aristotle</a>, it&#8217;s the only feedback I&#8217;ve had since I released it.</p>
<p>If I can figure these out, I should probably slap a 1.0 on it.</p>
<p>I also reckon I should do a talk on &#8220;Why we need another <span class="caps">XML</span> writer&#8221;.  There are quite a few on <span class="caps">CPAN</span> already and I should say why I wrote another one&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2006/06/07/xml-genx-plans/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>XML::Filter::Normalize 0.1</title>
		<link>http://happygiraffe.net/blog/2005/10/24/xml-filter-normalize-0-1/</link>
		<comments>http://happygiraffe.net/blog/2005/10/24/xml-filter-normalize-0-1/#comments</comments>
		<pubDate>Mon, 24 Oct 2005 21:25:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cpan]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sax]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2005/10/24/xml-filter-normalize-0-1/</guid>
		<description><![CDATA[A couple of days ago, I released]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago, I released <a href="http://search.cpan.org/<sub>hdm/XML-Filter-Normalize-0.01/&#8221;&gt;XML::Filter::Normalize</a>, in order to clean up a <span class="caps">SAX</span> event stream where possible.  Here&#8217;s <a href="http://aspn.activestate.com/ASPN/Mail/Message/perl-xml/2860913">Robin&#8217;s prodding</a>.  Anyway, it appears to work more or less as expected. I&#8217;m particularly pleased as it appears to have 100% test coverage.  Now, I just need to make <a href="http://search.cpan.org/</sub>hdm/XML-Genx-0.19/lib/XML/Genx/SAXWriter.pm&#8221;&gt;XML::Genx::SAXWriter</a> depend upon it in order to make Aristotle&#8217;s original problem go away.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2005/10/24/xml-filter-normalize-0-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>new XML::Genx</title>
		<link>http://happygiraffe.net/blog/2005/10/17/new-xml-genx/</link>
		<comments>http://happygiraffe.net/blog/2005/10/17/new-xml-genx/#comments</comments>
		<pubDate>Mon, 17 Oct 2005 07:38:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cpan]]></category>
		<category><![CDATA[genx]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2005/10/17/new-xml-genx/</guid>
		<description><![CDATA[XML::Genx 0.19 is now out. Changes include: Allow namespace objects to be passed in to StartElementLiteral() and AddAttributeLiteral(). This makes it much easier to put things into the default namespace. Add a missing &#8220;static&#8221; declaration to some XS helper functions. &#8230; <a href="http://happygiraffe.net/blog/2005/10/17/new-xml-genx/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://search.cpan.org/~hdm/XML-Genx-0.19/"><span class="caps">XML</span>::Genx 0.19</a> is now out.  Changes include:</p>
<ul>
<li>Allow namespace objects to be passed in to StartElementLiteral() and AddAttributeLiteral().  This makes it much easier to put things into the default namespace.</li>
<li>Add a missing &#8220;static&#8221; declaration to some XS helper functions.</li>
<li>Allow multiple different default namespaces inside <span class="caps">XML</span>::Genx::SAXWriter.  Previously you would get a &#8220;Duplicate Prefix&#8221; error.  Bug spotted by Aristotle Pagaltzis.</li>
<li>Make the tests work in perl 5.6.1.  Not sure when I broke this.</li>
</ul>
<p>I deliberately left out the <span class="caps">SAX</span> changes that Aristotle was talking about on the list, as I wanted some more feedback.  I&#8217;ll do another new release in a few days if nobody has said anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2005/10/17/new-xml-genx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML::Genx</title>
		<link>http://happygiraffe.net/blog/2005/10/15/xml-genx/</link>
		<comments>http://happygiraffe.net/blog/2005/10/15/xml-genx/#comments</comments>
		<pubDate>Sat, 15 Oct 2005 19:42:00 +0000</pubDate>
		<dc:creator>Dominic Mitchell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cpan]]></category>
		<category><![CDATA[genx]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://happygiraffe.net/2005/10/15/xml-genx/</guid>
		<description><![CDATA[Aristotle Pagaltzis has mentioned XML::Genx. Yay, it needs all the publicity that it can get. He highlighted some issues in XML::Genx::SAXWriter, which I need to address, although getting some consensus from the list first would be good. He also mentions &#8230; <a href="http://happygiraffe.net/blog/2005/10/15/xml-genx/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://plasmasturm.org/">Aristotle Pagaltzis</a> has <a href="http://aspn.activestate.com/ASPN/Mail/Message/Perl-XML/2858464">mentioned</a> XML::Genx.  Yay, it needs all the publicity that it can get.  He highlighted some issues in <span class="caps">XML</span>::Genx::SAXWriter, which I need to address, although getting some consensus from the list first would be good.</p>
<p>He also mentions a problem with <a href="http://aspn.activestate.com/ASPN/Mail/Message/perl-xml/2858721">default namespaces</a> a little further on.  I&#8217;ll have to look into that one.  I&#8217;m not sure if it&#8217;s a bug or Genx is supposed to work that way.</p>
<p>But it has made me realise that I need to upgrade the documentation that comes with Genx.  The <span class="caps">API</span> usage is not always as clear as it could be, particularly when it comes to namespaces and optional function arguments.  So a very good <span class="caps">EXAMPLES</span> section would do well I think.</p>
<p>Not only that, it&#8217;s also made realise that there&#8217;s some bad behaviour in there.</p>
<ol>
<li>Passing in a namespace object to <code>StartElementLiteral()</code> doesn&#8217;t work properly.  It assumes that the stringification of the namespace object is the <span class="caps">URL</span>.</li>
<li>The manner for using <code>StartElementLiteral()</code> to declare a default namespace sucks, badly.  You have to declare the namespace object with the default prefix (<em>ie</em>: &#8221;&#8221;).  Then, you have to call <code>StartElementLiteral()</code> passing in the <span class="caps">URI</span> yourself.  And then you have to call <code>AddNamespace()</code> on the namespace object to switch from the genx created prefix back to the default.  Very weird, but fixing the bug above would render this much simpler.</li>
</ol>
<p>It&#8217;s really important to get this sort of thing fixed up so that the <span class="caps">API</span> is easy to use and works as expected.</p>
<p>Finally, I&#8217;ve also noticed that the last release had an unexpected <a href="http://www.nntp.perl.org/group/perl.cpan.testers/259092">failure</a> (the Win32 stuff is at least <em>expected</em> failure).  What&#8217;s irritating is that it&#8217;s nothing to do with my code.  For some reason, version.xs is being picked up and mingled into my module.  I blame the person submitting the <span class="caps">CPAN</span> tester report (for now, anyway).  I&#8217;m sure I saw something about this on a <a href="http://use.perl.org/">use.perl.org</a> journal recently&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://happygiraffe.net/blog/2005/10/15/xml-genx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

