Section 5.2.  Mixing WordML with other vocabularies

Prev don't be afraid of buying books Next

5.2. Mixing WordML with other vocabularies

As we saw in 4.6, "Saving a document", on page 79, WordML can be interspersed with other vocabularies. When a Word document associated with a schema is saved as XML, by default the saved file contains both WordML elements and elements of the associated schema.

For example, saving an article document as XML results in a document that contains elements from the article schema interspersed with WordML elements, as shown in Example 5-9.

Example 5-9. article/WordML mixture (article data and WordML.xml)
 <ns0:section>   <ns0:header>     <w:p>       <w:pPr>         <w:pStyle w:val="Heading2"/>       </w:pPr>       <w:r>         <w:t>A great month!</w:t>       </w:r>     </w:p>   </ns0:header>   <ns0:para>     <w:p>       <w:r>         <w:t>This month's figures are a</w:t>       </w:r>       <ns0:em>         <w:r>           <w:rPr>             <w:i/>           </w:rPr>           <w:t>huge</w:t>         </w:r>       </ns0:em>       <w:r>         <w:t> improvement over this month last year. We sold 1,342 widgets for a total revenue of 14,327.</w:t>       </w:r>     </w:p>   </ns0:para> </ns0:section> 

Namespaces are used to distinguish between the two vocabularies. The WordML elements use the w prefix, as in w:p and w:t. The article vocabulary uses the ns0 prefix, as in ns0:section and ns0:header.

Because of the hierarchical structure of XML, an element from the article schema must always contain one or more entire WordML paragraphs, or be contained in a WordML paragraph. It is not possible for it to span part of one WordML paragraph plus part of the next paragraph.

In addition, each element from the article schema must contain its own text run. It cannot be included as a child of a text run element (r), nor as a child of a text element (t). For example, the following text run is illegal:

 <w:r><w:t><ns0:title>Sales Update</ns0:title></w:t></w:r> 

Instead, the ns0:title element should be moved out to contain the w:r element, as in:

 <ns0:title><w:r><w:t>Sales Update</w:t></w:r></ns0:title> 

Combining WordML with other vocabularies allows all of the Word formatting and other information to be retained, so that the document can be reopened in Word and the styles and settings will be intact. This is useful if you or other users will continue to edit the document in Word.

However, a mixed document is not valid according to the article schema. If you need an article document to pass to an application that is expecting it, just save the document as XML with the Save data only box checked.

Amazon


XML in Office 2003. Information Sharing with Desktop XML
XML in Office 2003: Information Sharing with Desktop XML
ISBN: 013142193X
EAN: 2147483647
Year: 2003
Pages: 176

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net