Create XSD from XML instance document – new JDeveloper 11gR1 feature


While looking into the XML functionality in JDeveloper 11g, I came across a feature that was added in the release – July 2009: [Create] XML Schema from XML Document. Functionality previously found in commercial products such as XMLSpy, that enables us to make a head start with the development of XML Schema Definitions by using an existing XML Document as starting point.

Create XSD from XML instance document - new JDeveloper 11gR1 featureIn this article, I will very briefly demonstrate what this functionality allows us to do. And what its current limitations are.

In short: we can indicate an XML document and have an XSD created that derives its element, type and attribute definitions from the actual XML content in that document. Most XML documents do not represent the entire set of restrictions and freedom that the XSD will describe, so the generated XSD is only a starting point – but a very useful one all the same.

At this moment, the XML source document has to exist on the file system (we cannot feed the tool with a URL). The created XSD document does not work well with multiple namespaces – as well will see in this example. The tool does not create named (complexTypes) – only (nested) elements. It does create, when so requested, simpleTypes with enumerations that describe all occurring values in the source XML document. Such enumerations are usually required only for a limited number of elements. Of course removing the types we do not need is not a lot of work. Yet it would be comfortable to specify in more detail for which elements to create these enumerations.

The example: I have created a source XML document from the RSS feed on this weblog ( have set the default namespace for this document. A snippet from the document:

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns="RSS_NS"
	<title>AMIS Technology blog</title>
	<atom:link href="" rel="self" type="application/rss+xml" />
	<description>Weblog for the AMIS Technology corner</description>
	<pubDate>Sat, 03 Oct 2009 07:00:24 +0000</pubDate>
	  <title>Book Review: Processing XML Documents with Oracle JDeveloper 11g by Deepak Vohra</title>
	  <pubDate>Sat, 03 Oct 2009 07:00:24 +0000</pubDate>
	  <dc:creator>Lucas Jellema</dc:creator>

Next I have used the XML Schema from XML Document option in the New Gallery. I selected the source XML document:

Create XSD from XML instance document - new JDeveloper 11gR1 feature

and had the XSD generated. In the visual editor, the XSD looks like this:

Create XSD from XML instance document - new JDeveloper 11gR1 feature

No named types, only elements with nested elements based on nested, anonymous complex type definitions. Well structured. With a proper global target namespace. And with strange handling of the other namespaces, especially the dc:creator element in the {}  namespace and likewise the atom:link element in the {} namespace.

<xsd:schema xmlns:xsd="" xmlns="RSS_NS"
            targetNamespace="RSS_NS" elementFormDefault="qualified">
  <xsd:element name="rss">
        <xsd:element name="channel">
              <xsd:element name="title" type="xsd:string"/>
              <xsd:element name="link" maxOccurs="unbounded">
                    <xsd:extension base="xsd:string">
                      <xsd:attribute name="href" type="xsd:string"/>
                      <xsd:attribute name="rel" type="xsd:string"/>
                      <xsd:attribute name="type" type="xsd:string"/>
              <xsd:element name="description" type="xsd:string"/>
              <xsd:element name="pubDate" type="xsd:string"/>
              <xsd:element name="generator" type="xsd:string"/>
              <xsd:element name="language" type="xsd:string"/>
              <xsd:element name="item" maxOccurs="unbounded">
                    <xsd:element name="title" type="xsd:string"/>
                    <xsd:element name="link" type="xsd:string"/>
                    <xsd:element name="comments" type="xsd:string"/>
                    <xsd:element name="pubDate" type="xsd:string"/>
                    <xsd:element name="creator" type="xsd:string"/>                     ...
      <xsd:attribute name="wfw" type="xsd:string"/>
      <xsd:attribute name="dc" type="xsd:string"/>
      <xsd:attribute name="atom" type="xsd:string"/>

This XSD is great first step – that you then have to take a little bit further. But for getting started with an XSD document, this is an excellent feature!


  1. Daniel Mouchaers October 7, 2009
  2. Marco Gralike October 7, 2009
  3. Marco Gralike October 7, 2009