Some Extra Study

Thursday, 5 June 2008 12:49 by frimbob

With an exam coming up on XML technologies, I needed to review some exercises. So I have decided to mix in some work with my Office application Project.

Word can attach a schema to a document and using that schema VSTO can create host controls for each xmlnode, this allows context sensitive menus using the document pane in office 2003.

I quickly developed and xml file who's nodes represent all the information found in a common template which the office app will be built on.

   1: <?xml version="1.0" standalone="no" ?>
   2: <articles>
   3:     <editorsmsg>I dont like this</editorsmsg> <!-- one per file  must be optional-->
   4:     <article id="1"> <!--need to number article --> 
   5:         <publishdate>24/04/08</publishdate> <!-- A valid Date value -->
   6:         <datewritten>23/04/08</datewritten> <!-- A valid Date value -->
   7:         <headline>Something Aint doing well</headline> <!-- Text only -->
   8:         <sections> <!-- Must choose one no maxium -->
   9:             <section></section> 
  10:             <section></section>
  11:             <section></section>
  12:         </sections>
  13:         <story>its a long story with images</story>     <!-- will contain HTML markup and text data needing escaped -->
  14:     </article>
  15:     <article id="2"> 
  16:         <publishdate>24/04/08</publishdate>
  17:         <datewritten>23/04/08</datewritten>
  18:         <headline>Sell Sell Sell</headline>
  19:         <sections>
  20:             <section></section>
  21:             <section></section>
  22:             <section></section>
  23:         </sections>
  24:         <story>its a long story with images</story>    
  25:     </article>
  26:     <article id="3"> 
  27:         <publishdate>24/04/08</publishdate>
  28:         <datewritten>23/04/08</datewritten>
  29:         <headline>Dont buy this</headline>
  30:         <sections>
  31:             <section></section>
  32:             <section></section>
  33:             <section></section>
  34:         </sections>
  35:         <story>its a long story with images</story>    
  36:     </article>
  37: </articles> 

Above is a copy of the xml document. (it is not a valid document), it was just to allow me to build a schema against.

The Schema

   1: <?xml version="1.0" standalone="yes" ?>
   2: <xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
   3:  xmlns:xs="http://www.w3.org/2001/XMLSchema">
   4:     <!--Named Data Types -->
   5:     <xs:simpleType name="sect">
   6:         <xs:restriction base="xs:string">
   7:             <xs:enumeration value="Inside the Market" />
   8:             <xs:enumeration value="Feature Stories " />
   9:             <xs:enumeration value="Stock In Focus" />
  10:             <xs:enumeration value="Air Bog " />
  11:             <xs:enumeration value="Market Movers" />
  12:             <xs:enumeration value="Air Daily" />
  13:             <xs:enumeration value="Mining and Resources" />
  14:         </xs:restriction>
  15:     </xs:simpleType>
  16:  
  17:     <!-- Section Type-->
  18:     <xs:element name="sections">
  19:         <xs:complexType>
  20:             <xs:sequence>
  21:                 <xs:element name="section" type="sect" minOccurs = "1" 
  22:                  maxOccurs = "6" />
  23:             </xs:sequence>
  24:         </xs:complexType>
  25:     </xs:element>    
  26:     
  27:     <!-- Articles -->
  28:     <xs:element name="article">
  29:         <xs:complexType>
  30:             <xs:sequence>
  31:                 <!-- Publish date -->
  32:                     <xs:element name="publishdate" type="xs:date" minOccurs="1" />
  33:                 <!-- Date Written -->    
  34:                     <xs:element name="datewritten" type="xs:date" minOccurs="1" />
  35:                 <!--Headline-->
  36:                     <xs:element name="headline" type="xs:string" minOccurs="1" />
  37:                 <!-- Section -->
  38:                     <xs:element ref="sections" minOccurs="1" />
  39:                 <!-- Story -->        
  40:                     <xs:element name="story" type="xs:string" minOccurs="1" />        
  41:             </xs:sequence>
  42:             
  43:             <!-- Article Attributes -->
  44:             <xs:attribute name="id" type="xs:integer" use="required"  />
  45:             
  46:             </xs:complexType>
  47:     </xs:element>
  48:     
  49:     <!-- Root Element -->
  50:     <xs:element name="articles">
  51:         <xs:complexType>
  52:             <xs:sequence>
  53:             <!-- Editors Comments -->
  54:             <xs:element name="editorsmsg" type="xs:string" minOccurs = "0" 
  55:              maxOccurs="1" />
  56:             <!-- Articles -->
  57:             <xs:element ref="article" minOccurs="1" maxOccurs="40" />
  58:             </xs:sequence>
  59:         </xs:complexType>
  60:     </xs:element>
  61: </xs:schema>

What did I learn?

There are 'named types' and there are 'named elements'. Using the node <xs:simpleType> declares a named type that must be imported in an element using the type="" declaration. While named elements must use the ref="" declaration to import and are declared between <xs:element> tags.

Types can be Derived through extension or restriction and the enumeration type is useful for drop-down lists.

The root element must be declared in the schema, in (DTD the root element is not considered).

Next I will develop the above xml-file into a DTD.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
Categories:  
Actions:   E-mail | Permalink | Comments (183) | Comment RSSRSS comment feed

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading