Friday, September 17, 2010

XML Schema: case of a "simple" element with text and one attribute

It has been a while since I worked with XML Schemas. But after immersing myself in delicious XML Schema material (to revamp Woodstox XML Schema support), I realized that it has not been nearly enough time.

That XML Schema is a very complex way of doing not so much more than what DTDs allow (basically, main tangible useful thing you get is plaing nice with namespaces -- necessary, but not much to write home about) is not news, but rather a recognized fact. But just how complicated AND verbose it is isn't obvious when you do not have write schemas. So here is the very first thing I had to do again: write a schema for single element with text as content, and a single text attribute. How much xml would that be? One or two lines?

No such luck. Unless I am mistaken, here's how to do it (adapted from Eric van der List's XML Schema book, highly recommended):

<xs:schema xmlns:xs=''>
 <xs:element name='price'>
     <xs:extension base='xs:int'>
       <xs:attribute name='currency' type='xs:string' />

God have mercy on us... this makes Java look like Forth in comparison. What were they thinking?

blog comments powered by Disqus

Sponsored By

Related Blogs

(by Author (topics))

Powered By

About me

  • I am known as Cowtowncoder
  • Contact me
Check my profile to learn more.