blob: 9b5c3b56a7ebfbe0e10061bf73cbf28b5b7738e8 [file] [log] [blame]
<?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">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../org.eclipse.wst.doc.user/common.css" />
<title>Reusing external parameter entities in an element's content model</title>
</head>
<body id="trusextp"><a name="trusextp"><!-- --></a>
<h1 class="topictitle1">Reusing external parameter entities in an element's content model</h1>
<div><p>Using an entity in a content model can save you time if you want
to have the same information in several content models. You can create a DTD
that references another DTD and then declares an element whose content model
refers to a parameter entity created in another DTD. </p><div class="skipspace"><p>The following instructions were written for the Resource perspective,
but they will also work in many other perspectives. </p>
<p>To create
a DTD that reuses an external parameter entity in an element's content model,
follow these steps:</p>
</div>
<ol><li class="skipspace"><span>Create a new DTD.</span> If you want to work with an existing
DTD, open your DTD in the DTD editor.</li>
<li class="skipspace"><span>Create an entity (for example, <kbd class="userinput">MyEntity</kbd>).</span></li>
<li class="skipspace"><span>Select <span class="uicontrol">Parameter</span> from the <span class="uicontrol">Entity
type</span> list, and type a value for the entity in the <span class="uicontrol">Entity
value</span> field. </span></li>
<li class="skipspace"><span>Save your DTD file.</span></li>
<li class="skipspace"><span>Create another DTD.</span></li>
<li class="skipspace"><span>Create another entity (for example, <kbd class="userinput">MySecondEntity</kbd>). </span></li>
<li class="skipspace"><span>Select <span class="uicontrol">Parameter</span> from the <span class="uicontrol">Entity
type</span> list and select the <span class="uicontrol">External</span> check
box to declare this as an external entity.</span></li>
<li class="skipspace"><span>In the <span class="uicontrol">System ID</span> field, type the path of
the DTD (or click the <span class="uicontrol">More</span> button to browse for a file)
you created in step 1 . The path is relative to the workspace root.</span></li>
<li class="skipspace"><span>(Optional) Type a value in the <span class="uicontrol">Public ID</span> field.</span></li>
<li class="skipspace"><span>In the Outline view, right-click the DTD and click <span class="uicontrol">Add
Parameter Entity Reference</span> to add a reference to the entity you
created in step 6 (for example, <kbd class="userinput">MySecondEntity</kbd>).</span></li>
<li class="skipspace"><span>Add an element.</span></li>
<li class="skipspace"><span>Change the content type for this element from EMPTY to the
value you specified in step 2 (for example,<kbd class="userinput">MyEntity</kbd>).</span> Note how you can select the value you specified in step 2 in the list
for the content element. This is because you included the first DTD that you
created in an earlier step.</li>
</ol>
<div class="skipspace"><p>You now have a DTD that references another DTD and declares an
element whose content model refers to a parameter entity created in the other
DTD. </p>
</div>
<div class="skipspace"><p>The following sample shows how you might reuse external parameter
entities in an element's content model.</p>
<p>You are making a list of everything
you have in both your work office and your home office. You have a computer
in each office and you do not want to write out a list of each part of your
computer more than once.</p>
<ol><li>Create a new DTD called <kbd class="userinput">WorkOffice.dtd.</kbd>.</li>
<li>Create the following four elements: <kbd class="userinput">Monitor</kbd>,<kbd class="userinput">Keyboard</kbd>, <kbd class="userinput">Mouse</kbd>,
and <kbd class="userinput">Hard_Drive</kbd>. Make the value of each element <span class="uicontrol">(#PCDATA)</span>.</li>
<li>Add an entity called <kbd class="userinput">WorkComp</kbd>. Select <span class="uicontrol">Parameter</span> as
the <span class="uicontrol">Entity type</span>. In the <span class="uicontrol">Value</span> field,
type: <kbd class="userinput">(Monitor, Keyboard, Mouse, Hard_Drive)</kbd>. Click
<span class="menucascade"><span class="uicontrol">File</span> &gt; <span class="uicontrol"> Save</span></span></li>
<li>Create another DTD called <kbd class="userinput">HomeOffice.dtd</kbd></li>
<li>Add an entity called <kbd class="userinput">HomeComp</kbd> to your HomeOffice.dtd
. Select <span class="uicontrol">Parameter</span> as the <span class="uicontrol">Entity type</span> and
click the <span class="uicontrol">External</span> check box to declare this as an
external entity. In the <span class="uicontrol">System ID</span> field, type the path
(or click the <span class="uicontrol">More</span> button to browse for the file) of <span class="uicontrol">WorkOffice.dtd</span>.
The path is relative to the workspace root.</li>
<li>(Optional) Type a value in the <span class="uicontrol">Public ID</span> field.</li>
<li>In the Outline view, right-click the DTD and select <span class="uicontrol">Add Parameter
Entity Reference</span> to add the entity you created earlier (that is,
%HomeComp;).</li>
<li>Add an element called <kbd class="userinput">MyHomeComp</kbd>. Change the content
model for MyHomeComp from <span class="uicontrol">EMPTY</span> to  <b>Work Office:
%WorkComp;</b>. The value of MyHomeComp is now: <b>Monitor Keyboard Mouse
Hard_Drive</b>.  Note how you can select the value you specified in step
4 in the <span class="uicontrol">Content type</span> list for the content element.
This is because you included the first DTD you created in an earlier step.</li>
</ol>
</div>
</div>
<div>
<p>
<b class="parentlink">Parent topic:</b> <a href="../topics/tcretent.html" title="An entity is a shortcut used to represent complex strings or symbols that would otherwise be impossible, difficult or repetitive to include by hand.">Creating entities</a><br />
</p>
<p><b class="reltaskshd">Related tasks</b><br />
<a href="../topics/trusents.html" title="Reusing the value of an entity in another entity can save you time in several ways. For example, if your value is long and complicated, it is much faster to simply reuse an entity than manually type in your value each time. As well, if the value changes, you only have to change it in one location.">Reusing the value of one entity in another entity</a><br />
<a href="../topics/trusintp.html" title="Reusing parameter entities in attributes can save you a lot of time. If you have several elements using the exact same attribute, you only have to input the information once (into an entity).  ">Reusing internal parameter entities in an attribute name or type</a><br />
</p>
</div><p>
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.
</p>
</body>
</html>