XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
=?UTF-8?Q?Re=3A_=5Bxml=2Ddev=5D_Don=E2=80=99t_create_elements_with_simple_co?==?UTF-8?Q?ntent_and_attributes?=

On Thu, Sep 27, 2018 at 6:24 PM Costello, Roger L. <costello@mitre.org> wrote:

Here is an element with simple content and an attribute:

<Cost currency="USD">8.95</Cost>

 

The data USD is explicitly labeled. The label indicates that USD is a currency.

What about the data 8.95, is it labeled? No! It is anonymous/unlabeled. Note: Cost is not the label for 8.95; Cost is the label for the whole package.

In my most recent post, I asked, “What is that number (8.95)?” I received excellent responses: 8.95 is a price, 8.95 is an amount, etc. External knowledge was needed to label the data. The need for external knowledge completely contradicts the fundamental axiom of XML.

Therefore, don’t create XML like this:

<Cost currency="USD">8.95</Cost>

instead, create XML like this:

<Cost>
   
<Currency>USD</Currency>
   
<Amount>8.95</Amount>
</Cost>


If you can use a schema, to validate an XML document, I think an XML like <Cost currency="USD">8.95</Cost> can be considered sufficiently labelled (8.95 as well). Following is my 1st attempt to create such a schema document for <Cost currency="USD">8.95</Cost>,

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="Cost">
     <xs:complexType>
       <xs:simpleContent>
          <xs:extension base="Amount">
             <xs:attribute name="currency" type="Currency" use="required"/>
          </xs:extension>
       </xs:simpleContent>
     </xs:complexType>
  </xs:element>
  
  <xs:simpleType name="Amount">
     <xs:restriction base="xs:decimal">
        <xs:minInclusive value="0"/>
     </xs:restriction>
  </xs:simpleType>
  
  <xs:simpleType name="Currency">
     <xs:restriction base="xs:string">
        <xs:enumeration value="USD"/>
        <xs:enumeration value="GBP"/>
     </xs:restriction>
  </xs:simpleType>

</xs:schema>



--
Regards,
Mukul Gandhi


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS