XML Schema Export and xsd:enumeration

473 views
Skip to first unread message

Schmitz, Jeffrey A

unread,
Apr 13, 2011, 2:01:30 PM4/13/11
to topbrai...@googlegroups.com

Hello,

   I’m using the XML Schema Export function on one of my models and was wondering if there is a way to export xsd enumerations from my model.  E.g. something like:

<xsd:simpleType name = "iso3currency">
    <xsd:restriction base = "xsd:string">
      <xsd:enumeration value = "AUD"/><!-- Australian Dollar -->
      <xsd:enumeration value = "BRL"/><!-- Brazilian Real -->
      <xsd:enumeration value = "CAD"/><!-- Canadian Dollar -->
      <xsd:enumeration value = "CNY"/><!-- Chinese Yen -->
      <xsd:enumeration value = "EUR"/><!-- Euro -->
      <xsd:enumeration value = "GBP"/><!-- British Pound -->
      <xsd:enumeration value = "INR"/><!-- Indian Rupee -->
      <xsd:enumeration value = "JPY"/><!-- Japanese Yen -->
      <xsd:enumeration value = "RUR"/><!-- Russian Rouble -->
      <xsd:enumeration value = "USD"/><!-- US Dollar -->
      <xsd:length value = "3"/>
    </xsd:restriction>
  </xsd:simpleType>
 

 

I tried using the owl:oneOf property in my model to define the enumeration values for a class, e.g.

 

<rdf:Description rdf:about="http://www.boeing.com/sem/acms/ACMS_Datalink_Report.owl#Suffix">

    <owl:oneOf rdf:resource="http://www.boeing.com/sem/acms/ACMS_Datalink_Report.owl#LDISP1"/>

    <owl:oneOf rdf:resource="http://www.boeing.com/sem/acms/ACMS_Datalink_Report.owl#REECGE"/>

    <owl:oneOf rdf:resource="http://www.boeing.com/sem/acms/ACMS_Datalink_Report.owl#TAKEOFF"/>

</rdf:Description>

  <Suffix rdf:about="http://www.boeing.com/sem/acms/ACMS_Datalink_Report.owl#LDISP1">

    <rdfs:label>LDISP1</rdfs:label>

  </Suffix>

 

but the exporter seems to ignore that.  Is there some other construct I could use?  If not, could this functionality perhaps be added to the exporter, perhaps using the enum resource’s local name or its rdfs:label property for the value used in the xml schema?  I’m no xml schema export, but it seems to me that on the surface they are two semantically equivalent concepts.

 

Thanks,
Jeff

Scott Henninger

unread,
Apr 14, 2011, 12:53:23 PM4/14/11
to TopBraid Suite Users
Jeff, the "XML Schemas from RDF/OWL" exporter does not support
enumerations in this way. It may be an enhancement we can look into
at some point.

In the meantime, you can accomplish this by converting the model into
Semantic XSD (see sxsd.rdf) and use the Semantic XML converter to
convert into XSD. For example, the following SPARQL transformation
will create a Semantic XSD structure that is converted to the XSD
shown in your question.

CONSTRUCT
{ ?schema composite:child ?cls .
?cls sxsd:name ?name .
?cls a sxsd:SimpleType .
?restr a sxsd:Restriction .
?restr sxsd:base "xsd:string" .
?cls composite:child ?restr .
?restr composite:child ?elem .
?elem a sxsd:Enumeration .
?elem sxsd:value ?enumName .
}
WHERE
{ ?cls (rdfs:subClassOf)+ owl:Thing .
?cls owl:oneOf ?oneOfList .
?oneOfList ((rdf:rest)*)/rdf:first ?elem .
LET (?name := smf:qname(?cls)) .
LET (?restr := smf:buildUniqueURI("restr_{?name}")) .
LET (?enumName := afn:localname(?elem)) .
}

...with ?schema bound to the root of the XSD file. While the
transformation may seem daunting at first glance, it's fairly simple
when broken down. The WHERE clause gets each class defined with a
owl:oneOf. For each match a <simpleType><restriction><enumeration>
tag hierarchy is created, along with the attributes for each.

With this, you can arrange your XSD tags any way you need. Let us
know how that works for you.

-- Scott

On Apr 13, 1:01 pm, "Schmitz, Jeffrey A"
Message has been deleted

Jeff

unread,
Apr 14, 2011, 4:53:22 PM4/14/11
to TopBraid Suite Users
When you say "converting the model into
Semantic XSD (see sxsd.rdf)"

Do you mean "coverting the originally generated xml schema file into
Semantic XSD"?

On Apr 14, 11:53 am, Scott Henninger <shennin...@topquadrant.com>
wrote:

Scott Henninger

unread,
Apr 14, 2011, 6:00:32 PM4/14/11
to topbrai...@googlegroups.com
By "Semantic XSD" I mean using Semantic XML with the extended tags and attributes defined in sxsd.rdf.  Note that sxsd.rdf imports sxml.rdf, so if you already have your RDF defined in Semantic XML, all you'd need to do is extend that for some schema definitions, such as the SPARQL transformation I sent earlier.

The XSD exporter was designed for minimal, least common denominator, mappings between OWL and XSD.  Extending that tool to include owl:oneOf-to-xsd:enumeration transformations seems reasonable and we will consider it.  That said it will be  a few weeks our before we could have an enhancement ready.

In the meantime, the sxsd.rdf mappings are the best route and has its advantages because can you fine-tune how your model creates the XML/XSD without interference with how different people may want to interpret OWL-XSD mappings.

-- Scott

On 4/14/11 3:41 PM, Schmitz, Jeffrey A wrote:
Hi Scott,
   When you say "converting the model into Semantic XSD (see sxsd.rdf)" I'm not quite sure I know what you mean.  Can you expand on that?  I see the example for enums, but would I have to write similar scripts to generate all the xsd constructs by "reverse engineering" the model, basically re-doing everything that I think the xml schema export functionality already does?  btw, my current model is based on sxml, e.g. all classes are subclasses of sxml:Element.

Thanks,
Jeff


</rdf:Description>
  <Suffix
rdf:about="http://www.boeing.com/sem/acms/ACMS_Datalink_Report.owl#LDIS
P1">
    <rdfs:label>LDISP1</rdfs:label>
  </Suffix>

but the exporter seems to ignore that.  Is there some other construct
I could use?  If not, could this functionality perhaps be added to the
exporter, perhaps using the enum resource's local name or its
rdfs:label property for the value used in the xml schema?  I'm no xml
schema export, but it seems to me that on the surface they are two
semantically equivalent concepts.
Thanks,
Jeff
--
You received this message because you are subscribed to the Google
Group "TopBraid Suite Users", the topics of which include TopBraid
Composer,
TopBraid Live, TopBraid Ensemble, SPARQLMotion and SPIN.
To post to this group, send email to
topbrai...@googlegroups.com
To unsubscribe from this group, send email to
topbraid-user...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/topbraid-users?hl=en

    

Schmitz, Jeffrey A

unread,
Apr 15, 2011, 9:31:15 AM4/15/11
to topbrai...@googlegroups.com

Hi Scott,

  I really like the idea of being able to “fine-tune how your model creates the XML/XSD without interference with how different people may want to interpret OWL-XSD mappings.”  But I’m missing something in how the basic mechanics would work to get TBC to spit out an xsd file without using the xsd exporter, and I want to be clear before heading down this road.  Here’s an example. 

 

In my sxml based model I have a Mnemonic element that is sub-classed from sxml:Element, along with a related mnemonic property:

:Mnemonic

      a       owl:Class ;

      rdfs:subClassOf <http://topbraid.org/sxml#Element> ;

      sxml:element "mnemonic"^^xsd:string .

 

:mnemonic

      a       owl:ObjectProperty ;

      rdfs:domain :ACMSReportFields ;

      rdfs:label "Mnemonic"^^xsd:string ;

      rdfs:range :Mnemonic ;

      rdfs:subPropertyOf <http://www.topbraid.org/2007/05/composite.owl#child> .

 

When I use the xsd exporter on this owl model I get the following schema definitions (not to mention all the definitions for the classes defined in  the sxml model itself and other imported models too, but that’s another issue). 

  <!--

    Created from class j.0:Mnemonic

     -->

  <xsd:element name="Mnemonic" type="MnemonicType"/>

  <xsd:complexType name="MnemonicType">

    <xsd:complexContent>

      <xsd:extension base="ElementType"/>

    </xsd:complexContent>

  </xsd:complexType>

 

  <xsd:element name="mnemonic">

    <xsd:complexType>

      <xsd:sequence>

        <xsd:element ref="Mnemonic"/>

      </xsd:sequence>

      <xsd:attribute name="IDREF" type="xsd:IDREF" use="optional"/>

    </xsd:complexType>

  </xsd:element>

 

This is great, but I’m not sure how to mimic this functionality by “extending your [sxml model] for some schema definitions, such as the SPARQL transformation I sent earlier.”  My most basic question is, how do I get TBC to spit out an xsd file without using the xsd exporter?  Or are you saying to use the xsd exporter to get an initial xsd, and then extend the xsd model (not my sxml based model) for some schema definitions…?

 

As an aside, is there a way to get TBC to spit out xml from an sxml based owl model?  I’m aware you can open an xml file directly and work with it using Semantic XML, but what if you aren’t starting out with an xml file, but with an owl model that you annotate with the required sxml annotations?

 

As always, Thanks!

jeff

Scott Henninger

unread,
Apr 15, 2011, 1:47:54 PM4/15/11
to topbrai...@googlegroups.com
Jeff; The first step may be to make sure you're aware of how Semantic XML works (Help > Import and Export > Creating, Importing, Querying, Saving XML documents with Semantic XML).  The second is that I'm assuming the use of a SPARQLMotion script to do the transformations. 

So a direct answer to how "to get TBC to spit out an xsd file without using the xsd exporter" is to write a script that uses sml:ConvertRDFToXML and returns that text or saves it in a file.  That is also the answer to "is there a way to get TBC to spit out xml from an sxml based owl model?".

Note that XSD and XML are being created the same way.  The basic difference is using sxml.rdf vs. sxsd.rdf for creating the different tags.  You may also find the attached script useful, as it will create a complex type for each class definition in any model and includes the owl:oneOf to xsd:enumeration transformation I did earlier.  This is an example of what I mean that you can fine tune this to meet your needs.  The basic principle is the RDF structure in Semantic XML and providing the transforms that put your RDF into that format so you can run
sml:ConvertRDFToXML and get the xsd formatted the way you want it.

If you really want to get deep into this, have a look at the XML SchemaPlus Specification (http://xspl.us/xsp-spec.html).  This gets really deep into the complexities of RDF/OWL to XSD conversions.  Basically it defines extensions to XSD to make transformations between RDF/OWL and XSD easier.  This is a bit more than our current out-of-box XSD exporter currently addresses, and I'd suggest a follow-up with Ralph or Gokhan if you are interested in that.

-- Scott
demo.sms.ttl
unnamed0.ttl

Schmitz, Jeffrey A

unread,
Apr 16, 2011, 2:49:55 PM4/16/11
to topbrai...@googlegroups.com

Thanks Scott,

   The thing I was really missing was using SPARQLMotion and the ConvertRDFToXML Module, and your script has provided a great head start for me on using it.

 

I think I have a pretty good handle on the overall concept but (as usual) there are a couple other finer points that aren’t quite clear to me are:

 

1.       In sxsd.rdf, why are many of the classes annotated with 3 different values for the sxml:element property (e.g. xsd:schema, xs:schema, schema for the Schema class) and perhaps more importantly, how when generating with ConvertRDFToXML can you choose which one to use?

2.       How does the sxml:prefix property work?  I see that I can specify this property on my schema object with values such as “xsd” and “rdf” and it automatically picks the URI to associate with that namespace.  How does it do this? and what if it chooses wrong?  And what if I want to use “xs” instead of “xsd”?

 

Thanks,

Jeff

Scott Henninger

unread,
Apr 19, 2011, 9:46:55 PM4/19/11
to topbrai...@googlegroups.com
Jeff; See inline responses:


On 4/16/11 1:49 PM, Schmitz, Jeffrey A wrote:

Thanks Scott,

   The thing I was really missing was using SPARQLMotion and the ConvertRDFToXML Module, and your script has provided a great head start for me on using it.

 

I think I have a pretty good handle on the overall concept but (as usual) there are a couple other finer points that aren’t quite clear to me are:

 

1.       In sxsd.rdf, why are many of the classes annotated with 3 different values for the sxml:element property (e.g. xsd:schema, xs:schema, schema for the Schema class) and perhaps more importantly, how when generating with ConvertRDFToXML can you choose which one to use?


The sxsd.rdf module is used for some of our xsd importers, and those use the different choices of the sxml:element properties.  It is the case that sxml:element determines how the XML tag will be rendered.  I've attached another version of the script that takes an argument for the prefix used in the xsd.  The FilterSXMLElements module removes all sxml:element properties and AddSXMLElements replaces sxml:element properties with any prefix (including none).

It also aligns the namespace with the sxml:prefix property per below.

2.       How does the sxml:prefix property work?  I see that I can specify this property on my schema object with values such as “xsd” and “rdf” and it automatically picks the URI to associate with that namespace.  How does it do this? and what if it chooses wrong?  And what if I want to use “xs” instead of “xsd”?


The purpose of sxml:prefix is to add xmlns declarations.  It will only add declarations for those prefixes the script knows about.  The script now includes a couple of other prefixes, added with sml:ModifyPrefixes, that can be used.  So if you enter "abc" as the prefixChoice, "abc:" will be used for the xsd element prefixes and an xmlns attribute will be added for "abc".  Using "xs" instead of "xsd" is trickier because "xsd" is defined in the default model.  However, you could use the ModifyPrefixes module to remove the "xsd" prefix and add the "xs" prefix.

Not sure I mentioned before that this script can be call via a Web service, e.g.:
  http://localhost:8083/tbl/actions?action=sparqlmotion&id=createXSD&baseURI=http://support.tq.com/testxsd0&prefixChoice=abc

-- Scott
demo.sms.ttl
Reply all
Reply to author
Forward
0 new messages