|
Home > Online Product Documentation > Table of Contents > Using Schemas with XML Documents Using Schemas with XML DocumentsStylus Studio allows you to associate one or more schemas with each XML document. A schema can be a DTD or an XML Schema. There are several ways to associate a schema with an XML document:
This section discusses the following topics: Associating an External Schema With a DocumentTo associate an external schema with an XML document:
1. Open the XML document you want to associate with a schema. See
Opening Files in Stylus Studio.
2. From the Stylus Studio menu bar, select
XML
>
Associate XML with Schema.
3. In the
Open dialog box that appears, navigate to and select the schema you want to associate.
4. Click
Open. The selected schema is now associated with the document.
To associate an XML document with an XML Schema, the XML document must contain a root element. After you associate a schema with a document, you can view a tree representation of the schema in the XML editor window. Click the Schema tab. See Updating a Document's Schema. Having Stylus Studio Generate a SchemaIn the XML editor, you can click the Schema tab to view the schema for your document. If your document does not specify a schema, Stylus Studio displays the Schema Not Found dialog box. This dialog box prompts you to indicate whether you want Stylus Studio to create a schema for your document based on its contents. You can select Generate XML Schema or Generate DTD. If you select Generate XML Schema, you must specify an absolute path for the file that contains the new schema. If you select Generate DTD, you must indicate whether you want the DTD to be internal or external. If it is internal, Stylus Studio inserts it immediately after the XML declaration. If it is external, you must specify or select an absolute path for the file that contains the new DTD. After you click OK, Stylus Studio displays the new schema in the Schema tab. Validating XML Documents
At any time, you can validate your XML document against its schema. Click
Validate Document
Stylus Studio displays a message that indicates whether or not your document is valid. If your document does not conform to its schema, Stylus Studio displays a list of error messages that describe the inconsistencies. This list includes line and column numbers that indicate the location of the error. When you click in an XML document, Stylus Studio shows the line and column number in the bottom right corner of the Stylus Studio window. When Stylus Studio validates a document, it also checks for well-formedness. Stylus Studio uses font color to indicate valid and invalid element names. Purple fonts indicate valid elements. Orange fonts indicate elements that are not in the schema.
Updating a Document's SchemaHow you update your document's schema depends on whether the schema is internal or external. If the schema is an internal DTD, you can update it in the Schema tab of the XML editor. If the schema is not an internal DTD, you can update it only in the DTD editor or the XML Schema editor. You can, however, view the schema in the Schema tab of the XML editor. When Stylus Studio displays the schema for your document, you can also view the properties for each node in the schema. If the Properties window is not already in view, select View > Properties. Click on any node in the schema view to see the properties for that node.
To view the text of an external schema or to edit an external schema, you must display it in the DTD editor or the XML Schema editor. To do this, select
XML
>
Open Associated Schema from the Stylus Studio menu bar, or click
Open Schema
Instructions for updating a DTD are in Chapter 8Defining Document Type Definitions. Instructions for updating an XML Schema are in Creating an XML Schema in Stylus Studio. If you update a schema in Stylus Studio and that schema is associated with an XML document that is open in Stylus Studio, Stylus Studio refreshes the schema information for the open XML document. Removing the Association Between a Document and a SchemaTo remove the association between a document and an external schema, you must edit the XML document in the Text or Tree tab. Remove the text or nodes that specify the external schema. To remove an internal DTD from a document, delete the text or nodes that specify the internal DTD. |

Cart

