Section 4.7.  Combining documents

Prev don't be afraid of buying books Next

4.7. Combining documents

In Chapter 1, "Desktop XML: The reason why", on page 4, we learned about Denise, who is responsible for putting the newsletter together from many articles. One of the nice things about using XML is that all the articles Denise receives have the same XML markup, making her compilation job easier. Simply by opening the incoming articles in Word, she can validate them against the article schema to ensure that they meet her standards; for example, that they all have a title.

4.7.1 Combining elements from multiple namespaces

Denise has a newsletter skeleton document, shown in Example 4-3, that she uses when creating a newsletter. As we saw in 4.2.3, "Opening a skeleton document", on page 73, a skeleton is simply an XML document without the data content. Because Denise is the only user, and prefers to see the tag icons so that she knows what is going on with the XML representation, she did not bother with placeholder text for the skeleton.

Example 4-3. Newsletter skeleton document (newsletter temp.xml)
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <newsletter xmlns="http://xmlinoffice.com/newsletter">   <volume></volume>   <number></number>   <date></date>   <body> <!--body must contain one or more article elements -->   </body> </newsletter> 

She also has a newsletter schema, shown in Example 4-4, whose target namespace is http://xmlinoffice.com/newsletter. According to the BodyType definition, the body element of a newsletter can contain one or more article elements.

Example 4-4. Newsletter schema (newsletter.xsd)
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <xs:schema targetNamespace="http://xmlinoffice.com/newsletter"            xmlns="http://xmlinoffice.com/newsletter"            xmlns:art="http://xmlinoffice.com/article"            xmlns:xs="http://www.w3.org/2001/XMLSchema"            elementFormDefault="qualified">   <xs:import namespace="http://xmlinoffice.com/article"              schemaLocation="article.xsd"/>   <xs:element name="newsletter" type="NewsletterType"/>   <xs:complexType name="NewsletterType">     <xs:sequence>       <xs:element name="volume" type="xs:integer"/>       <xs:element name="number" type="xs:integer"/>       <xs:element name="date" type="xs:string"/>       <xs:element name="body" type="BodyType"/>     </xs:sequence>   </xs:complexType>   <xs:complexType name="BodyType">     <xs:sequence>       <xs:element ref="art:article" maxOccurs="unbounded"/>     </xs:sequence>   </xs:complexType> </xs:schema> 

This combining of elements from more than one namespace is not unusual, and Word supports it. When Word opens a newsletter document, it knows it must also use the article schema, because of the import element in the newsletter schema.

4.7.2 Compiling document fragments

Denise has three choices for compiling the articles: cutting and pasting elements, copying and inserting documents, and linking to documents.

4.7.2.1 Cutting and pasting elements

One straightforward way to put the newsletter together is to cut and paste article elements into the newsletter document. Word supports the cutting and pasting of XML fragments to and from documents.

When Denise opens her newsletter skeleton in Word, it looks something like Figure 4-9. She can then cut the article elements from the various article XML documents that were submitted to her, and paste them into the newsletter document.

Figure 4-9. Word presentation of the newsletter skeleton




Because the newsletter schema requires the children of body to be article elements (i.e. root elements from the article schema), inserting the articles will not cause any errors to be raised. If the elements had been from any other vocabulary, she would still be able to paste them, but errors would be flagged in the XML Structure task pane.

4.7.2.2 Copying and inserting documents

Another method is to insert entire article documents into the newsletter document. To do this:

1. Position your cursor in the desired insert location.

2. On the Insert menu, click File.

3. Select an article XML file, such as article.xml.

4. Click Insert.

Word will insert the entire document as a child of the current element. If a default solution stylesheet is specified (in the Schema Library) for the article document, it is applied automatically when the article is inserted into the newsletter.

4.7.2.3 Linking to documents

Another possibility is to insert links to the article files, so that if the articles are updated in the future, the newsletter will be updated as well. This method is useful if Denise needs to begin compiling the newsletter before the articles are finished. To do this:

1. Position your cursor in the desired insert location.

2. On the Insert menu, click File.

3. Select an article XML file, such as article.xml.

4. Click the down arrow just to the right of the Insert button.

5. Click Insert as Link.

To refresh the newsletter after an article file has been updated, you can select the linked article elements and press F9. Alternatively, you can right-click an article start-tag and click Update Field, as shown in Figure 4-10.

Figure 4-10. Refreshing a linked document




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