<?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>non-random ramble &#187; xml</title>
	<atom:link href="http://jimbarritt.com/non-random/category/code/xml/feed/" rel="self" type="application/rss+xml" />
	<link>http://jimbarritt.com/non-random</link>
	<description>adventures in code</description>
	<lastBuildDate>Tue, 20 Sep 2011 13:16:52 +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>XStream collections: when is an ArrayList not an ArrayList ?</title>
		<link>http://jimbarritt.com/non-random/2009/11/25/xstream-collections-when-is-an-arraylist-not-an-arraylist/</link>
		<comments>http://jimbarritt.com/non-random/2009/11/25/xstream-collections-when-is-an-arraylist-not-an-arraylist/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 15:29:44 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdk]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=315</guid>
		<description><![CDATA[I was just getting the following output from XStream when trying to serialize an object which has a collection property: &#60;addresses class="java.util.Arrays$ArrayList"> &#60;a class="address-array"> &#60;address> It had to step through the code to see what was going on. The key is in the subtlety of the type of the list that I was putting in [...]]]></description>
			<content:encoded><![CDATA[<p>I was just getting the following output from XStream when trying to serialize an object which has a collection property:</p>
<pre>
&lt;addresses class="java.util.Arrays$ArrayList">
&lt;a class="address-array">
&lt;address>
</pre>
<p>It had to step through the code to see what was going on.</p>
<p>The key is in the subtlety of the type of the list that I was putting in there. Notice that actually its not an <code>java.util.ArrayList</code> its actually an inner class of the <code>Arrays</code>, called, happily <code>$ArrayList</code>, so I had been staring at it the whole time and not noticed.</p>
<p>When XStream serializes its doing the following:</p>
<pre name='code' class='java:nogutter:nocontrols'>
        Class actualType = newObj.getClass();
        Class defaultType = mapper.defaultImplementationOf(fieldType);
        if (!actualType.equals(defaultType)) {
            String serializedClassName = mapper.serializedClass(actualType);
            if (!serializedClassName.equals(mapper.serializedClass(defaultType))) {
                String attributeName = mapper.aliasForSystemAttribute(&#8220;class&#8221;);
                if (attributeName != null) {
                    writer.addAttribute(attributeName, serializedClassName);
                 }
            }
        }
</pre>
<p>From version 1.3.1 &#8211; <code>AbstractReflectionConverter:127</code></p>
<p>So its asking the mapper what the default implementation of the type is. The type in this case was <code>java.util.List</code> and the default implementation is of course <code>java.util.ArrayList</code>. It is not seeing <code>java.util.Arrays$ArrayList</code> as the same thing and so thinks it needs to specify it.</p>
<p>Now you might be asking, how come I have a strange inner class version of <code>ArrayList</code> ? Well the thing is, I thought I was being clever in the set up of my test data and im using:</p>
<pre name='code' class='java:nogutter:nocontrols'>
       addresses = Arrays.asList(
                new AddressBuilder().addressType(&#8220;home&#8221;).streetAddress(&#8220;1 The street&#8221;).build(),
                new AddressBuilder().addressType(&#8220;work&#8221;).streetAddress(&#8220;2 The street&#8221;).build(),
                new AddressBuilder().addressType(&#8220;holiday&#8221;).streetAddress(&#8220;3 The street&#8221;).build()
        );
</pre>
<p>To set up my test data. <code>asList</code> does this:</p>
<pre name='code' class='java:nogutter:nocontrols'>
 public static  List asList(T&#8230; a) {
	return new ArrayList(a);
    }
    private static class ArrayList extends AbstractList
	implements RandomAccess, java.io.Serializable
    {
        private static final long serialVersionUID = -2764017481108945198L;
	private Object[] a;
</pre>
<p>Where it uses its own implementation of ArrayList.</p>
<p>Phew, another fun couple of hours spent there.</p>
<p></e></t></p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F11%2F25%2Fxstream-collections-when-is-an-arraylist-not-an-arraylist%2F&amp;title=XStream%20collections%3A%20when%20is%20an%20ArrayList%20not%20an%20ArrayList%20%3F"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/11/25/xstream-collections-when-is-an-arraylist-not-an-arraylist/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The matching wildcard is strict, but no declaration can be found</title>
		<link>http://jimbarritt.com/non-random/2009/11/20/the-matching-wildcard-is-strict-but-no-declaration-can-be-found/</link>
		<comments>http://jimbarritt.com/non-random/2009/11/20/the-matching-wildcard-is-strict-but-no-declaration-can-be-found/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 12:43:07 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[xsd]]></category>

		<guid isPermaLink="false">http://jimbarritt.com/non-random/?p=303</guid>
		<description><![CDATA[I&#8217;ve just painfully bruised my brain against this error message when trying to validate an xml against its schema. The problem is that it is hiding what is really going on, which is that it could not match the namespace uri in the schema document to the one in my xml document. The xml: &#60;?xml [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just painfully bruised my brain against this error message when trying to validate an xml against its schema.</p>
<p>The problem is that it is hiding what is really going on, which is that it could not match the namespace uri in the schema document to the one in my xml document.</p>
<p>The xml:</p>
<pre>
&lt;?xml version="1.0" encoding="UTF-8"?>
&lt;feed xmlns="http://www.w3.org/2005/Atom"
      xmlns:h="http://some.custom.schema">

    &lt;title>/v2/people/facebook.com/@self&lt;/title>
    &lt;updated>2003-12-13T18:30:02Z&lt;/updated>

    &lt;h:callId>b702ae86-b07f-4e2f-b49f-27d1a79b7783&lt;/h>
&lt;/feed>
</pre>
<p>The xsd</p>
<pre>
&lt;xs:schema elementFormDefault="qualified"
                      targetNamespace="http://some.target.namespace.which.does.not.match"
                      xmlns="http://some.target.namespace.which.does.not.match"
                      xmlns:xs="http://www.w3.org/2001/XMLSchema">
&lt;/xs>
</pre>
<p>Check it.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2009%2F11%2F20%2Fthe-matching-wildcard-is-strict-but-no-declaration-can-be-found%2F&amp;title=The%20matching%20wildcard%20is%20strict%2C%20but%20no%20declaration%20can%20be%20found"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2009/11/20/the-matching-wildcard-is-strict-but-no-declaration-can-be-found/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Output XSD Schema From XSLT Transformation</title>
		<link>http://jimbarritt.com/non-random/2006/03/21/output-xsd-schema-from-xslt-transformation/</link>
		<comments>http://jimbarritt.com/non-random/2006/03/21/output-xsd-schema-from-xslt-transformation/#comments</comments>
		<pubDate>Mon, 20 Mar 2006 22:30:37 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[xml]]></category>
		<category><![CDATA[xsd]]></category>
		<category><![CDATA[xslt]]></category>

		<guid isPermaLink="false">http://www.planet-ix.com/non-random/2006/03/21/output-xsd-schema-from-xslt-transformation/</guid>
		<description><![CDATA[Well i needed to know how to generate a schema from XSLT which means you need to output the first line of the schema definition which wasnt too intuitive so here is the result: hmmm &#8211; cant paste it in here &#8211; see attatched file!! XSLT Transformation to Generate an XSD schema Ok it was [...]]]></description>
			<content:encoded><![CDATA[<p>Well i needed to know how to generate a schema from XSLT which means you need to output the first line of the schema definition which wasnt too intuitive so here is the result:</p>
<p>hmmm &#8211; cant paste it in here &#8211; see attatched file!!</p>
<p><a href="http://jimbarritt.com/non-random/wp-content/uploads/2006/03/generate_schema_xsd.txt">XSLT Transformation to Generate an XSD schema</a></p>
<p>Ok it was MUCH simpler than i thought of course! you simply type in the whole thing into the xslt and it just prints it out! so you dont need to use xs element at all doh!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2006%2F03%2F21%2Foutput-xsd-schema-from-xslt-transformation%2F&amp;title=Output%20XSD%20Schema%20From%20XSLT%20Transformation"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2006/03/21/output-xsd-schema-from-xslt-transformation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Schemas With JAXP</title>
		<link>http://jimbarritt.com/non-random/2006/01/25/using-schemas-with-jaxp/</link>
		<comments>http://jimbarritt.com/non-random/2006/01/25/using-schemas-with-jaxp/#comments</comments>
		<pubDate>Tue, 24 Jan 2006 23:16:20 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.planet-ix.com/non-random/2006/01/25/using-schemas-with-jaxp/</guid>
		<description><![CDATA[If you want to use schemas such as : When you create the document factory you have to tell it to become namespace aware : static final String JAXP_SCHEMA_LANGUAGE = &#8220;http://java.sun.com/xml/jaxp/properties/schemaLanguage&#8221;; static final String W3C_XML_SCHEMA = &#8220;http://www.w3.org/2001/XMLSchema&#8221;; try { factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA); } catch (IllegalArgumentException x) { // Happens if the parser does not support JAXP [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to use schemas such as :</p>
<p><someRootNode xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br />
xmlns:xs="http://www.w3.org/2001/XMLSchema"></p>
<p>When you create the document factory you have to tell it to become namespace aware :</p>
<p>static final String JAXP_SCHEMA_LANGUAGE =<br />
&#8220;http://java.sun.com/xml/jaxp/properties/schemaLanguage&#8221;;</p>
<p>static final String W3C_XML_SCHEMA =<br />
&#8220;http://www.w3.org/2001/XMLSchema&#8221;;<br />
try {<br />
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);<br />
}<br />
catch (IllegalArgumentException x) {<br />
// Happens if the parser does not support JAXP 1.2<br />
throw new XMLValidationException(&#8220;Could not create validating XML Parser &#8221; + x.getMessage(), x);<br />
}</p>
<p>THis lets it understand, otherwise you get :</p>
<p>org.xml.sax.SAXParseException: Document is invalid: no grammar found.<br />
org.xml.sax.SAXParseException: Document root element &#8220;EClaim_Message&#8221;, must match DOCTYPE root &#8220;null&#8221;.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2006%2F01%2F25%2Fusing-schemas-with-jaxp%2F&amp;title=Using%20Schemas%20With%20JAXP"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2006/01/25/using-schemas-with-jaxp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Filtering a view which is based on an xml CLOB</title>
		<link>http://jimbarritt.com/non-random/2006/01/24/filtering-a-view-which-is-based-on-an-xml-clob/</link>
		<comments>http://jimbarritt.com/non-random/2006/01/24/filtering-a-view-which-is-based-on-an-xml-clob/#comments</comments>
		<pubDate>Tue, 24 Jan 2006 04:36:02 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.planet-ix.com/non-random/2006/01/24/filtering-a-view-which-is-based-on-an-xml-clob/</guid>
		<description><![CDATA[Ok, so you create a table which has an xml blob. THen you create a view onto that table which maps elements inside the XML blob to columns in the view, thus &#8220;expanding&#8221; out the xml to look like a normal table. To do this you use the extract() method in oracle (see other posts) [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so you create a table which has an xml blob.</p>
<p>THen you create a view onto that table which maps elements inside the XML blob to columns in the view, thus &#8220;expanding&#8221; out the xml to look like a normal table.</p>
<p>To do this you use the extract() method in oracle (see other posts) .</p>
<p>Now you want to filter the view based on nodes which are inside the xml data but oracle wont let you do it directly because the columns arent real columns.</p>
<p>SO</p>
<p>You need to include a unique key in the view &#8211; then you can do the select on the original table and JOIN the view to it! bit convoluted but it works! as long as there is a unique key of course &#8211; so you might have to design your xml table with this in mind but even if this is arbitrary it will still work.</p>
<p>here is an example :</p>
<p>SELECT tbview.* FROM TABLE_ONE tb, TABLE_ONE_VIEW tbview<br />
WHERE<br />
tbview.UNIQUE_ID=tb.UNIQUE_ID<br />
AND<br />
tb.XML_COLUMN.existsNode(&#8216;/some/expath[with_test_node="TEST_2"]&#8216;)=1;</p>
<p>Sweet!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2006%2F01%2F24%2Ffiltering-a-view-which-is-based-on-an-xml-clob%2F&amp;title=Filtering%20a%20view%20which%20is%20based%20on%20an%20xml%20CLOB"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2006/01/24/filtering-a-view-which-is-based-on-an-xml-clob/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Query Using XPATH</title>
		<link>http://jimbarritt.com/non-random/2006/01/24/sql-query-using-xpath/</link>
		<comments>http://jimbarritt.com/non-random/2006/01/24/sql-query-using-xpath/#comments</comments>
		<pubDate>Tue, 24 Jan 2006 04:02:15 +0000</pubDate>
		<dc:creator>Jim Barritt</dc:creator>
				<category><![CDATA[databases]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.planet-ix.com/non-random/2006/01/24/sql-query-using-xpath/</guid>
		<description><![CDATA[eg : WHERE tb.XML_COLUMN.existsNode(&#8216;/some/xpath[with_test="Jeff"]&#8216;)=1 have to use this &#8220;existsNode&#8221; the xpath can then do the filter &#8211; if you want to filter on the value of a node you do the above, otherwise use @ for attributes.]]></description>
			<content:encoded><![CDATA[<p>eg :</p>
<p>WHERE tb.XML_COLUMN.existsNode(&#8216;/some/xpath[with_test="Jeff"]&#8216;)=1</p>
<p>have to use this &#8220;existsNode&#8221; the xpath can then do the filter &#8211; if you want to filter on the value of a node you do the above, otherwise use @ for attributes.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fjimbarritt.com%2Fnon-random%2F2006%2F01%2F24%2Fsql-query-using-xpath%2F&amp;title=SQL%20Query%20Using%20XPATH"><img src="http://jimbarritt.com/non-random/wp-content/plugins/add-to-any/share_save_256_24.png" width="256" height="24" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://jimbarritt.com/non-random/2006/01/24/sql-query-using-xpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

