Exporting the Mapped XML in the Document to an XML Data File





Exporting the Mapped XML in the Document to an XML Data File

With the document mapped to our XML schema, let's save this document to XML conforming to the book order schema we have used. First, make sure you save your document as a .doc file so that you do not lose your work. After you have saved the document, from the File menu choose the Save As command. From the Save as type drop-down list, choose XML Document. Two check boxes appear in the dialog: Apply transform and Save data only. Make sure the Save data only check box is checked, as shown in Figure. Then Click the Save button. Word will warn you that it is only going to save out XML and not any formatting. If you have already saved your document as a .doc file, click the Continue button to save as XML. When you open the saved XML, it will look like Listing 22-1.

Saving as an XML document with Save data only checked.


There are some other ways to save to XML that will not generate our book order XML. If save data only is not checked, Word will save the document in an XML format called WordprocessingML, or WordML for short. WordML is an XML file format that Word documents can be saved in that preserves all the formatting and features of a Word document. If you look at the WordML XML file that is generated for this example, you will notice that the WordML schema is used to represent Word content. The book order schema is also used in the saved WordML document to mark up any content that we schema mapped. In the snippet of the WordML file shown in Listing 22-4, you can see that the WordML file format uses the CustomerName element to mark up the customer name (John Doe), but what is marked up is the WordML representation of the customer name rather than just the simple text John Doe.

-4. A Snippet of WordML Representing the Customer Name Label and XML Mapped CustomerName
<w:p>
     <w:r>
          <w:t>Customer Name: </w:t>
     </w:r>
     <w:r>
          <w:tab wx:wTab="555" wx:tlc="none" wx:cTlc="8"/>
     </w:r>
     <ns0:CustomerName>
          <w:r>
               <w:t>John Doe</w:t>
          </w:r>
     </ns0:CustomerName>
</w:p>

You can also use a transform when saving by checking the Apply transform box. A transform is an XSLT file that acts on the WordML XML file and transforms it to some other XML format. For example, you could create an XSLT transform that takes a WordML XML file and transforms it to XML conforming to the book order schema. This does not seem necessary because clicking the Save data only option already does this. There are compelling scenarios around a similar scenario: importing XML data and applying a transform to convert it to a nicely formatted document in WordML. The next section examines this scenario in more detail.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows