blob: ab8acd73ddf4f6992cb14896c443f5b6e1c3c7f9 [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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
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" />
5<meta name="copyright" content="Copyright (c) 2000, 2006 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 http://www.eclipse.org/legal/epl-v10.html. Contributors: IBM Corporation - initial API and implementation" />
6<meta name="DC.rights.owner" content="(C) Copyright 2000, 2006" />
7<meta content="public" name="security" />
8<meta content="index,follow" name="Robots" />
9<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" 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" />
12<meta name="abstract" content="In the Design view, when you edit an XML file that has a set of constraints (that is, a set of 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 (that is, a set of 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 DTD or XML schema constraints, XML files, with DTD or XML schema constraints" name="DC.subject" />
15<meta content="XML editor, editing, with DTD or XML schema constraints, XML files, with DTD or XML schema constraints" name="keywords" />
16<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>
31
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
35
36
37
syeshinbefd53e2005-07-27 18:16:40 +000038<div><p>In the Design view, when you edit an XML file that has a set of
39constraints (that is, a set of rules) defined by a DTD or an XML schema, you
40can turn the constraints on and off to provide flexibility in the way you
kpriceef160682006-08-29 18:08:31 +000041edit, but still maintain the validity of the document periodically.</p>
42
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
48options.</p>
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
54for an XML file off, click <span class="uicontrol">XML &gt; Turn Grammar Constraints Off</span>.
55After you have turned the constraints off for a file, you can insert or delete
56any element or attribute regardless of the DTD or XML schema rules. You can
57create new elements or attributes that are not in the DTD or schema - these
58Design view prompts will only appear when you have turned constraints off.
kpriceef160682006-08-29 18:08:31 +000059The file might not be valid, however, if you do this. </p>
60<p>The following
61instructions were written for the Resource perspective, but they will also
62work in many other perspectives.</p>
63<p>The following example shows what you
64can do if you turn the constraints of a DTD off:</p>
syeshinbefd53e2005-07-27 18:16:40 +000065</div>
kpriceef160682006-08-29 18:08:31 +000066
67<ol>
68<li class="stepexpand"><span>Open the XML file in the XML editor (right-click the file in the
69Navigator view and click <span class="uicontrol">Open With &gt; XML Editor</span>). </span>
syeshinbefd53e2005-07-27 18:16:40 +000070</li>
kpriceef160682006-08-29 18:08:31 +000071
72<li class="stepexpand"><span>You have a DTD that specifies that an element requires at least
73one of a specific child element: </span> <pre>&lt;!ELEMENT parentElement (childElement+)&gt;
74</pre>
75</li>
76
77<li class="stepexpand"><span>If, in an XML file associated with your DTD, you attempt to remove
syeshinbefd53e2005-07-27 18:16:40 +000078the final child element of the element with the DTD constraints turned on,
kpriceef160682006-08-29 18:08:31 +000079the editor will not allow you to do this, as it will make the document invalid.</span>
80 You can confirm this by using the element's pop-up menu to verify that
81the <span class="uicontrol">Remove</span> option is grayed out.</li>
82
83<li class="stepexpand"><span>To turn the DTD constraints off, click <span class="uicontrol">XML &gt; Turn Grammar
84Constraints Off</span>. </span></li>
85
86<li class="stepexpand"><span>If you attempt to remove the same child element with constraints
syeshinbefd53e2005-07-27 18:16:40 +000087off, the editor will allow you to.</span></li>
kpriceef160682006-08-29 18:08:31 +000088
89<li class="stepexpand"><span>To correct the invalid document, you will have to re-add the necessary
syeshinbefd53e2005-07-27 18:16:40 +000090element, or remove the invalid tagging or value.</span></li>
kpriceef160682006-08-29 18:08:31 +000091
syeshinbefd53e2005-07-27 18:16:40 +000092</ol>
kpriceef160682006-08-29 18:08:31 +000093
94<div class="section">If you introduce errors into your files, you must save and validate
syeshinbefd53e2005-07-27 18:16:40 +000095the file in order to see a list of the errors you have introduced. They will
96be listed in the Problems view. After you fix the errors, you must save and
97validate your file again to see if the file is now valid.</div>
kpriceef160682006-08-29 18:08:31 +000098
syeshinbefd53e2005-07-27 18:16:40 +000099</div>
100
kpriceef160682006-08-29 18:08:31 +0000101<div><div class="relconcepts"><strong>Related concepts</strong><br />
102<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 +0000103</div>
kpriceef160682006-08-29 18:08:31 +0000104<div class="reltasks"><strong>Related tasks</strong><br />
105<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>
106<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 Uniform Resource Identifier (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>
107<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>
108<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>
109</div>
110</div>
111
syeshinbefd53e2005-07-27 18:16:40 +0000112</body>
113</html>