1
votes

I need to make an xsd file for CodeSynthesis's XSD. There will be multiple schemas for different response types. As you can see in a sample XML file some elements have a type attribute, and some have nil attribute. These attributes provide no info for parsing, I already know types and set them in xsd file properly. Besides that, I don't know which elements are nillable. Can these attributes be some way skipped in xsd schema, or I should write for each element:

<xsd:complexType>
    <xsd:attribute name="type" type="TypeAttr" fixed="integer"/>
    <xsd:attribute ref="nil"/>
</xsd:complexType>

where

<xsd:attribute name="nil" type="xsd:boolean"/>

That's one of the XML files:

<?xml version="1.0" encoding="UTF-8"?>
<account>
  <access-key>bla-bla-bla</access-key>
  <billing-error-date type="date" nil="true"></billing-error-date>
  <default-ticket-report-id type="integer">0</default-ticket-report-id>
  <default-time-zone nil="true"></default-time-zone>
  <description nil="true"></description>
  <disk-usage type="integer">38048</disk-usage>
  <flagged-for-billing-error type="boolean">false</flagged-for-billing-error>
  <force-ssl type="boolean">false</force-ssl>
  <id type="integer">1</id>
  <plan>micro</plan>
  <subdomain>companyname</subdomain>
  <text-markup>markdown,textile,plain</text-markup>
  <title>companyname</title>
  <features>
    <attachments>true</attachments>
    <ssl>false</ssl>
    <storage>512</storage>
    <time_tracking>false</time_tracking>
    <max_people>10</max_people>
    <max_pages>99999</max_pages>
    <beta>false</beta>
  </features>
  <notebook_pages>0</notebook_pages>
  <created-at>2011-02-16T13:50:09Z</created-at>
  <updated-at>2011-04-07T09:11:10Z</updated-at>
</account>
1
According to w3.org/TR/2001/REC-xmlschema-0-20010502/#Nils the nil must have the xsi namespace; is this a typo or is the attribute name just nil (and an attribute just like any other)?ThomasRS
It is just an attribute like any other, xsi namespace is not used here. However it is used to indicate empty elements too.vian
yeah well your question becomes really generic when it is just any attribute ;)ThomasRS
You might find marxsoftware.blogspot.com/2008/11/… interesting :PThomasRS

1 Answers

0
votes

I used the following to add type and nil attribute support.

<xsd:complexType name="UString">
  <xsd:simpleContent>
    <xsd:extension base="xsd:string">
      <xsd:attribute name="type" type="TypeAttr" fixed="string" use="optional"/>
      <xsd:attribute name="nil" type="xsd:boolean" use="optional"/>
    </xsd:extension>
  </xsd:simpleContent>
</xsd:complexType>

<xsd:complexType name="UInteger">
  <xsd:simpleContent>
    <xsd:extension base="xsd:integer">
      <xsd:attribute name="type" type="TypeAttr" fixed="integer" use="optional"/>
      <xsd:attribute name="nil" type="xsd:boolean" use="optional"/>
    </xsd:extension>
  </xsd:simpleContent>
</xsd:complexType>

<xsd:simpleType name="TypeAttr">
  <xsd:restriction base="xsd:string">
    <xsd:enumeration value="datetime"/>
    <xsd:enumeration value="integer"/>
    <xsd:enumeration value="boolean"/>
  </xsd:restriction>
</xsd:simpleType>