views:

132

answers:

5

We recently started providing a data extract to clients via an XML. We have a schema (XSD) that defines the structure of this XML. I would like to include the documentation of the elements and attributes in the schema itself. The only thing I am finding is the very cumbersome "annotation" and "documentation" tags.

So you take something as simple and easy to read as this:

<xs:element name="TransactionType" type="xs:string"  />

And end up with this ugly mess:

<xs:element name="TransactionType" type="xs:string">
    <xs:annotation>
     <xs:documentation>
      Type of transaction
     </xs:documentation>
    </xs:annotation>
</xs:element>

Is there anything better? Say something like this:

<xs:element name="TransactionType" type="xs:string" description="Type of transaction"  />

PS: We already provided this extract as a simple fixed length file and as a CSV. One client requested an XML and we now have a second client wanting to use the XML. I got asked for documentation. The first client for whom we originally developed the XML version just wanted an XSD. Hence my hope to just send the second client one document -- the XSD with simple annotations describing the elements.

+1  A: 

No, there is not. <xs:annotation><xs:documentation> is all there is.

John Saunders
That's a shame. It will actually make the schema harder to read. I probably will now end up creating a second document.
JohnOpincar
You seem to be assuming that someone will read the schema. What do you base that assumption on?
John Saunders
The fact that it would be the only thing I would give the potential consumer of this extract in the form of documentation.
JohnOpincar
As I suggested, I wouldn't assume they'll read the schema, or that they'll understand it. If you want them to understand the format, then you'll have to do something different, like maybe write some documentation in a human language.
John Saunders
A: 

XSD provide the tags you mention for documentation. I agree with you, they are cumbersome and makes your files even more bigger.

Unortunately that is what we have.

Luixv
A: 

Yes, this is cumbersome, but unfortunately it is the only mechanism for documentation. However, the annotation tag is provided to meet many needs. You can put computer processing instructions in there, you can put human-readable documentation in there.

XSD is designed more, I think, to convey information effectively to a computer program. For example, if you are running a code generator from a schema, the code generator can include the annotation element information in code self-documentation, such as JavaDoc or equivalents for other languages.

Also, the annotation documentation tag can include text of an arbitrary length. It can include HTML tags and in fact arbitrary XML. This is why it is not an attribute, but an element.

Eddie
Well, my XSD right now is very easy to read. The annotations would make it literally 4 times larger and no longer human readable. I don't dispute that the annotation tags are very flexible but they don't server the needs of simplicity.
JohnOpincar
You are absolutely correct. No-one is disagreeing with you.
Eddie
+2  A: 

Are you aware that you can easily transform your XSD - even with the cumbersome annotation and documentation tags - into a fairly nicely readable HTML documentation file?

The magic is called xs3p and it's a fairly substantial XSLT file to convert your XSD (which is just another XML after all) into nicely structured, very useful documentation HTML.

It's free, it works - just great! :-)

Of course - you still have to add the annotation/documentation to your XSD, but it might be a better solution than having a XSD and a separate documentation file (which most likely will be out of sync sooner or later......)

Marc

marc_s
I'm trying to avoid unnecessary complexity. It amazes me that the designers of XSD couldn't foresee this. I have a very simple XSD. Adding all the extra elements will make it 4 times as large. And then I have to do an XSLT transformation. I was hoping to just send out the XSD by itself and have it self-documenting.
JohnOpincar
Welcome to the XML-based world! :-)
marc_s
A: 

I have a suggestion - why don't you write the schemas in the way you propose, i.e.

<xs:element name="TransactionType" type="xs:string" description="Type of transaction" />

and pass it through an XSLT to transform that into the full format of

<xs:element name="TransactionType" type="xs:string"> 
 <xs:annotation> 
  <xs:documentation> Type of transaction </xs:documentation> 
 </xs:annotation> 
</xs:element>

You give out the transformed XSD to customers, internally you use the compact version.

JonoW
My hope was to just send out the XSD by itself and have it self-documenting.
JohnOpincar