englishteeth.co.uk

… the weblog of Ian “English Teeth” Robinson
  • rss
  • Home

Freeware XSD Editor

April 30, 2008 | 7:31 pm

I wanted to generate some sample XML from an XSD I was given and I was struck by the lack of resources outside of the over bloated Altova tools and their misguided clones much more heavy weight options that seem overkill for what I’m trying to do.

I was actually hoping to find a style sheet that could do the job, but I had no luck.

Along the way though, I did find Liquid XML Studio which in it’s freeware incarnation has some nice schema viewing, editing and generation features. There’s also an integrated web service browser



and although, I haven’t played with it much yet, there’s an XPath expression builder in there too.



My only disappointment is the lack of XSLT support, at least in the freeware version. I’m looking for a reasonable successor to MarrowSoft Xselerator which is no longer supported or being sold by TopXML. Xselerator is not compatible with Microsoft Internet Explorer 7, which I has not actually proved a problem for me yet, but it’s days must be numbered.

I’m not adverse to paying for software (Xselerator wasn’t free), but I must admit to being put off a little by hobbled versions. An issue covered much better than I could by Jeff Atwood, here.

My favourite Cyberlink love/hate thing comes to mind; Power DVD Ultra, Power DVD Deluxe, Power DVD Standard or Power DVD OEM. Mmm, now let me see… do any of them work reliably?

Comments
3 Comments »
Categories
development, software
Tags
freeware, webservice, xml, xpath, xsd, xslt
Comments rss Comments rss
Trackback Trackback

Simple URIReslover

March 25, 2008 | 11:09 am

I don’t mind admitting that despite it being pretty straight forward, I have been caught out by this more than once. So, in an attempt to prevent that Doh! moment again in the future…

The scenario revolves around an XSL Stylesheet that references another resource, be it an XML file for lookups, another stylesheet or whatever. Everything works a treat when processed locally, but blows up when invoked in its Java context. “Can not load requested doc:” or something similar.

This is where brain failure kicks in and I can’t think where the resource should be and waste time moving files around, changing references and trawling the web. In fact the reason the document cannot be found is simply because I haven’t told the transformer where, or more acurately how, to look for it!

The following is a simple reslover that looks on the class path for the missing file.

	public class ResourceResolver implements URIResolver {

		private static final String RESOURCE_PREFIX = "resource://"; 

		public Source resolve(String href, String base)
				throws TransformerException {
			if (!href.startsWith(RESOURCE_PREFIX))
				return null;
			try {
				if (log.isDebugEnabled()) {
					log.debug("Resolving stylesheet resource: " + href);
				}
				String resource = href.substring(RESOURCE_PREFIX.length());
				ClassLoader loader = getClass().getClassLoader();
				InputStream is = loader.getResourceAsStream(resource);
				return new StreamSource(is, resource);
			} catch (Exception ex) {
				throw new TransformerException(ex);
			}
		}
	}

Comments
No Comments »
Categories
development, software
Tags
java, xml, xslt
Comments rss Comments rss
Trackback Trackback

XSL “Is Numeric” too

February 27, 2008 | 12:14 pm

Building on a previous post Oracle “Is Numeric” a similar thing is possible using XSLT (or more accurately, XPATH) too…

<xsl:if test="string-length(translate(node(),' +-.1234567890', ' ')) > 0">
  <xsl:text&gt;not numeric&lt;/xsl:text>
</xsl:if>

Not exactly ground breaking stuff, but something similar did turn out useful for extracting the non numerical area component of a post code (i.e. the SO bit of SO53 3RY).

substring-before(translate($postcode,'1234567890', '----------'),'-')

Which I thought was close enough to the oracle is numeric implementation to make comment.

Comments
No Comments »
Categories
development, software
Tags
xml, xpath, xslt
Comments rss Comments rss
Trackback Trackback

Augmenting XML using XSLT

January 16, 2008 | 10:42 am

In order to augment a piece of XML using XSLT, the base requirement is to make sure the existing document or fragment is preserved. This is done by recursively copying all the elements, attributes etc. as defined by the W3C Recommendation for copying.

<xsl:template match="@*|node()">
  <xsl:copy>;
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

The main things going are here is the matching of every attribute with “@*” and every child node (node() being shorthand for child::node()). As mentioned in the W3C Recommendation, the root node is considered a special case and is implicit, therefore “@*|node()” finds everything else.

This is all well and good, but the benefit of this recurisve copying is making the exceptions or augmentations to the input XML. To implement these we simply add templates matching the point of change:

<xsl:template match="existingElement" >
  <xsl:element name="replacementElement">
    <xsl:text>Some content for the new element</xsl:text>
  </xsl:element>
</xsl:template>

A really good description and set of examples of doing this sort of thing (also known as the identity template) can be found here.

Comments
No Comments »
Categories
development, software
Tags
xml, xslt
Comments rss Comments rss
Trackback Trackback

Author

Ian Robinson is a relatively agile software engineer interested in things both sides of the object relational divide and beyond.

Categories

  • development (35)
  • miscellaneous (20)
  • music (7)
  • software (13)

Blogroll

  • Dan North
  • Dave Astels
  • Dave Wood
  • eirikso.com
  • Matt Raible
  • Object Mentor Blog
  • The Ancient Art of Programming
  • The Wisdom of Ganesh

Tags

active-mq architecture bauhaus blu-ray css db eclipse esb festivals freesat gorm grails groovy hd hd-dvd hibernate java jboss jms junit links mce media center mini music oracle osgi patterns pirsig plugins satellite soa software spring sql struts2 testing themes tools tv web wordpress xml xpath xslt
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox