Section 15.4. Attaching an XML Schema to Your Document


15.4. Attaching an XML Schema to Your Document

The word schema sounds a little nefarious or at least seriously geeky . But a schema is simply a document that acts as a Rosetta stone for XML files describing the content. For an example, see Figure 15-3. Don't panic; you may never have to create a schema on your own. It's more likely that some day you'll want to attach a schema somebody else created to a Word document. For example, suppose you're a realtor who wants to tap into a database of homes that are on the market. You could create a document listing all the homes , along with details such as the number of rooms and the number of baths and the price. The folks who created the database could give you the name and location of a schema on the Internet. When you attach that schema to your document, you can display the information from the database in content controls in your Word document.

Here's how to attach a schema to your Word document:

  1. Open the document you want to use with the XML information with the command Office Open .

    The Open dialog box shows on your screen. Use it to find and open your file.

  2. Choose Developer XML Schema to open the Templates and Add-ins box (Figure 15-5) .

    The Templates and Add-ins box has several tabs at the top. When you open it with the Schema command, it automatically shows the XML Schema tab. The Available XML schemas box shows any schemas that are currently attached to your document.


    Note: If the Developer tab isn't showing on your ribbon, go to Section 14.2.2 for instructions on how to make the Developer tab visible.

    Figure 15-5. Use the XML Schema tab on the Templates and Add-ins dialog box to attach schemas to your document. The available schemas appear in the large box. Click to place a checkmark next to a schema and to attach it to your document. You can attach more than one schema to a document.


  3. Click the Add Schema button to open the Add Schema box .

    The Add Schema box looks like any standard Windows file box. Using the buttons on the left and the drop-down menu at the top, navigate to the location with the schema you're adding to your document. If the document is located on a network, use the My Network Places button in the lower-left corner of the Add Schema box.

  4. Navigate to the schema file, and then double-click to select the .xsd file .

    The Add Schema box closes , and the Schema Settings box opens. Most likely, the URI and Location boxes are already filled in with details that tell Word where to find information about the schema. You can fill in a name for the schema in the Alias text box.

  5. Click the OK to close the Schema settings and to return to the XML Schema tab of the Templates and Add-ins box .

    The Schema you just attached appears in the "Available XML schemas" box. Make sure a checkmark appears next to the name so you can use it with your document. You can have several schemas installed and available in Word. Just use the checkboxes to attach a specific schema to your document.

  6. Click OK to close the Templates and Add-ins box .

    Once the Template and Add-ins box closes, it probably looks like nothing has changed in your document. However, a change has taken place behind the scenes. Because a new schema is attached to your document, you can see the available tags in the XML Structure pane, as shown in Figure 15-6.

Once you've attached a custom XML schema to your document, you see a list of the XML elements that are defined by the schema in the XML Structure pane. To open the pane, go to Developer Structure or use the keyboard shortcut Alt+L, T. You use the elements listed in the XML Structure pane to apply custom tags to the text in your document. To apply a tag, select the text you want to tag, and then choose an element from the XML Structure pane.

Figure 15-6. The XML Structure pane keeps track of the XML tags that are used in your document in the box at the top and gives you a list of the available tags in the box at the bottom.


POWER USERS' CLINIC
XML Primer for HTML Writers

This chapter makes it clear that XML serves a much different purpose than HTML. In spite of that, their method for marking up documents is much the same. They use tags that look similar. But if you're familiar with HTML and want to take a crack at creating some XML documents, there are a few gotchas to watch out for.

In many cases, the rules for creating XML are strict, while the rules for HTML are flexible. If an XML document doesn't conform to the rules, it's considered an invalid document, and programs designed to use XML simply ignore it. Here's a short list of some of the differences between HTML and XML:

  • XML code is case-sensitive . When you write HTML code, it really doesn't matter if the characters inside the tags are uppercase or lowercase. A bold tag can be <b> or <B>. Browsers don't care a bit. With XML, there's a big difference. To a program reading XML, the tags <TITLE>, <Title>, and <title> are three entirely different tags.

  • Tags must be used in pairs, with one exception being the empty tag . HTML writers get a little freeform with tags. Even though paragraphs should have a beginning tag <p> and an end tag </p>, many Web pages simply use the beginning tag, and most Web browsers don't seem to mind that the closing tag is missing. XML isn't as forgiving .

    Because it's important to know where data begins and ends, you need to use both beginning and end tags. The exception is what's known as an empty taga type of tag that never has any content. Empty tags use a special form, with a slash before the last angle bracket . So, an empty tag may look like this: <nothingness/>; it means the same thing to XML programs as this: <nothingness></ nothingness >.

  • Tags must be properly nested . Another area where HTML coders get a little footloose is the order in which they place tags, for example: <outside> <inside>Great American Novel</outside></inside>. Technically, the closing </inside> tag should be next to the text, just like the opening one is. Most browsers forgive this kind of error, but XML programs doesn't. Tags must be properly nested, or XML programs will consider them invalid

  • In XML, white space is considered intentional . Web browsers don't pay much attention to tabs, line breaks, and paragraph marks unless they're told to with special instructions such as <pre> tags. XML takes a different approach. If you have 45 space characters between each word in your book title, XML assumes that you put them there on purpose.




Word 2007[c] The Missing Manual
Word 2007[c] The Missing Manual
ISBN: 059652739X
EAN: N/A
Year: 2006
Pages: 180

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