blob: 3574b49d94078d49b6003fcc507442aecd6cab1e [file] [log] [blame]
kpriceef160682006-08-29 18:08:31 +00001<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
2<html lang="en-us" xml:lang="en-us">
syeshinbefd53e2005-07-27 18:16:40 +00003<head>
kpriceef160682006-08-29 18:08:31 +00004<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
kpriceb59c9f62008-04-02 21:24:37 +00005<meta name="copyright" content="Copyright (c) 2000, 2008 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at Contributors: IBM Corporation - initial API and implementation" />
6<meta name="DC.rights.owner" content="(C) Copyright 2000, 2008" />
kpriceef160682006-08-29 18:08:31 +00007<meta content="public" name="security" />
8<meta content="index,follow" name="Robots" />
9<meta http-equiv="PICS-Label" content='(PICS-1.1 "" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "" l gen true r (n 0 s 0 v 0 l 0) "" l gen true r (SS~~000 1))' />
10<meta content="task" name="DC.Type" />
11<meta name="DC.Title" content="Editing with DTD or XML schema constraints" />
kpriceb59c9f62008-04-02 21:24:37 +000012<meta name="abstract" content="In the Design view, when you edit an XML file that has a set of constraints or rules defined by a DTD or an XML schema, you can turn the constraints on and off to provide flexibility in the way you edit, but still maintain the validity of the document periodically." />
13<meta name="description" content="In the Design view, when you edit an XML file that has a set of constraints or rules defined by a DTD or an XML schema, you can turn the constraints on and off to provide flexibility in the way you edit, but still maintain the validity of the document periodically." />
14<meta content="XML editor, editing with constraints, XML files" name="DC.subject" />
15<meta content="XML editor, editing with constraints, XML files" name="keywords" />
kpriceef160682006-08-29 18:08:31 +000016<meta scheme="URI" name="DC.Relation" content="../topics/cxmlcat.html" />
17<meta scheme="URI" name="DC.Relation" content="../topics/tedtdoc.html" />
18<meta scheme="URI" name="DC.Relation" content="../topics/txmlcat.html" />
19<meta scheme="URI" name="DC.Relation" content="../topics/tedtgram.html" />
20<meta scheme="URI" name="DC.Relation" content="../topics/cxmlcat.html" />
21<meta scheme="URI" name="DC.Relation" content="../topics/tedtsch.html" />
22<meta scheme="URI" name="DC.Relation" content="../topics/txmlcat.html" />
23<meta scheme="URI" name="DC.Relation" content="../topics/tedtgram.html" />
24<meta content="XHTML" name="DC.Format" />
25<meta content="tedtcnst" name="DC.Identifier" />
26<meta content="en-us" name="DC.Language" />
27<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
syeshinbefd53e2005-07-27 18:16:40 +000028<title>Editing with DTD or XML schema constraints</title>
syeshin66078272005-09-20 16:53:38 +000029</head>
syeshinbefd53e2005-07-27 18:16:40 +000030<body id="tedtcnst"><a name="tedtcnst"><!-- --></a>
kpriceef160682006-08-29 18:08:31 +000032
syeshinbefd53e2005-07-27 18:16:40 +000033<h1 class="topictitle1">Editing with DTD or XML schema constraints</h1>
kpriceef160682006-08-29 18:08:31 +000034
syeshinbefd53e2005-07-27 18:16:40 +000038<div><p>In the Design view, when you edit an XML file that has a set of
kpriceb59c9f62008-04-02 21:24:37 +000039constraints or rules defined by a DTD or an XML schema, you can turn the constraints
40on and off to provide flexibility in the way you edit, but still maintain
41the validity of the document periodically.</p>
kpriceef160682006-08-29 18:08:31 +000042
43<div class="section"><p> When the constraints are turned on, and you are working in the
syeshinbefd53e2005-07-27 18:16:40 +000044Design view, the XML editor prevents you from inserting elements, attributes,
45or attribute values not permitted by the rules of the XML schema or DTD, and
46from removing necessary or predefined sets of tags and values. In this mode,
47an element's content must be valid to use the XML editor's guided editing
kpriceef160682006-08-29 18:08:31 +000049<p>You might want to turn the constraints off for an XML file
50if you need more flexibility. For example, you want to try working with elements
syeshinbefd53e2005-07-27 18:16:40 +000051or attributes not permitted by the associated DTD or XML schema, without actually
52removing the association with the DTD or XML schema.</p>
53<p>To turn the constraints
kpriceb59c9f62008-04-02 21:24:37 +000054for an XML file off, click <span class="menucascade"><span class="uicontrol">XML</span> &gt; <span class="uicontrol">Turn
55Grammar Constraints Off</span></span> in the toolbar. After you
56have turned the constraints off for a file, you can insert or delete any element
57or attribute regardless of the DTD or XML schema rules. You can create new
58elements or attributes that are not in the DTD or schema - these Design view
59prompts will only appear when you have turned constraints off. The file might
60not be valid, however, if you do this. </p>
61<p>The following example shows
62what you can do if you turn the constraints of a DTD off:</p>
syeshinbefd53e2005-07-27 18:16:40 +000063</div>
kpriceef160682006-08-29 18:08:31 +000064
66<li class="stepexpand"><span>Open the XML file in the XML editor (right-click the file in the
67Navigator view and click <span class="uicontrol">Open With &gt; XML Editor</span>). </span>
syeshinbefd53e2005-07-27 18:16:40 +000068</li>
kpriceef160682006-08-29 18:08:31 +000069
70<li class="stepexpand"><span>You have a DTD that specifies that an element requires at least
71one of a specific child element: </span> <pre>&lt;!ELEMENT parentElement (childElement+)&gt;
75<li class="stepexpand"><span>If, in an XML file associated with your DTD, you attempt to remove
syeshinbefd53e2005-07-27 18:16:40 +000076the final child element of the element with the DTD constraints turned on,
kpriceef160682006-08-29 18:08:31 +000077the editor will not allow you to do this, as it will make the document invalid.</span>
78 You can confirm this by using the element's pop-up menu to verify that
79the <span class="uicontrol">Remove</span> option is grayed out.</li>
81<li class="stepexpand"><span>To turn the DTD constraints off, click <span class="uicontrol">XML &gt; Turn Grammar
82Constraints Off</span>. </span></li>
84<li class="stepexpand"><span>If you attempt to remove the same child element with constraints
syeshinbefd53e2005-07-27 18:16:40 +000085off, the editor will allow you to.</span></li>
kpriceef160682006-08-29 18:08:31 +000086
87<li class="stepexpand"><span>To correct the invalid document, you will have to re-add the necessary
syeshinbefd53e2005-07-27 18:16:40 +000088element, or remove the invalid tagging or value.</span></li>
kpriceef160682006-08-29 18:08:31 +000089
syeshinbefd53e2005-07-27 18:16:40 +000090</ol>
kpriceef160682006-08-29 18:08:31 +000091
kpriceb59c9f62008-04-02 21:24:37 +000092<div class="section"><p>If you introduce errors into your files, you must
93save and validate the file in order to see a list of the errors you have introduced.
94They will be listed in the Problems view. After you fix the errors, you must
95save and validate your file again to see if the file is now valid.</p>
97instructions were written for the Resource perspective, but they will also
98work in many other perspectives.</p>
kpriceef160682006-08-29 18:08:31 +0000100
syeshinbefd53e2005-07-27 18:16:40 +0000101</div>
kpriceef160682006-08-29 18:08:31 +0000103<div><div class="relconcepts"><strong>Related concepts</strong><br />
104<div><a href="../topics/cxmlcat.html" title="When an XML file is associated with a DTD or XML schema, it is bound by any structural rules contained in the DTD or XML schema. To be considered a valid XML file, a document must be accompanied by a DTD or an XML schema, and conform to all of the declarations in the DTD or the XML schema.">XML file associations with DTDs and XML schemas</a></div>
syeshin66078272005-09-20 16:53:38 +0000105</div>
kpriceef160682006-08-29 18:08:31 +0000106<div class="reltasks"><strong>Related tasks</strong><br />
107<div><a href="../topics/tedtdoc.html" title="The DOCTYPE declaration in an XML file is used at the beginning of it to associate it with a DTD file. You can edit your DOCTYPE declaration to change the DTD file your XML file is associated with.">Editing DOCTYPE declarations</a></div>
kpriceb59c9f62008-04-02 21:24:37 +0000108<div><a href="../topics/txmlcat.html" title="An XML Catalog entry contains two parts - a Key (which represents a DTD or XML schema) and a Location (similar to a URI, which contains information about a DTD or XML schema's location). You can place the Key in an XML file. When the XML processor encounters it, it will use the XML Catalog entry to find the location of the DTD or XML schema associated with the Key">Adding entries to the XML Catalog</a></div>
kpriceef160682006-08-29 18:08:31 +0000109<div><a href="../topics/tedtgram.html" title="If you make changes to a DTD file or XML schema associated with an XML file (that is currently open), click XML &gt; Reload Dependencies to update the XML file with these changes. The changes will be reflected in the guided editing mechanisms available in the editor, such as content assist.">Updating XML files with changes made to DTDs and schemas</a></div>
110<div><a href="../topics/tedtsch.html" title="Your namespace information is used to provide various information about the XML file, such as the XML schema and namespace it is associated with. If desired, you can change the schema and namespace your XML file is associated with or add a new association. Modifying any associations can impact what content is allowed in the XML file.">Editing namespace information</a></div>
syeshinbefd53e2005-07-27 18:16:40 +0000114</body>