blob: 345e9b5e459d453fe5396ae3d59faa26c255aa9a [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<!-- /*******************************************************************************
* Copyright (c) 2000, 2005 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
*******************************************************************************/ -->
<link rel="stylesheet" type="text/css" href="../../org.eclipse.wst.doc.user/common.css" />
<title>Working with XML templates</title>
<body id="twmacro"><a name="twmacro"><!-- --></a>
<h1 class="topictitle1">Working with XML templates</h1>
<div><p>XML content assist provides a comment template, a chunk of predefined
code that you can insert into a file.&nbsp; You may find a template useful when
you have a certain piece of code you want to reuse several times, and you do
not want to write it out every time.</p>
<div class="skipspace">You can use the default template as
provided, customize that template, or create your own templates. For example, you may work on a group of XML pages that should all
contain a table with a specific appearance. Create a template that contains
the tags for that table, including the appropriate attributes and attribute
values for each tag. (You can copy and paste the tags from a structured text
editor into the template's <b>Pattern</b> field.) Then select the name of the template
from a content assist proposal list whenever you want to insert your custom
table into an XML file.<p>To create a new XML template follow these steps:</p>
<ol><li class="skipspace"><span>Click <b> <span class="menucascade"><span class="uicontrol">Window</span> &gt; <span class="uicontrol">Preferences</span> &gt; <span class="uicontrol">Web and XML</span> &gt; <span class="uicontrol">XML Files</span> &gt; <span class="uicontrol">XML
<li class="skipspace"><span>Click <b> <span class="uicontrol">New</span></b> if you want to create a completely
new template.</span></li>
<li class="skipspace"><span>Supply a new template <b>Name</b> and <b>Description</b>.</span></li>
<li class="skipspace"><span>Specify the <b> <span class="uicontrol">Context</span></b> for the template.</span> This is the context in which the template is available in the proposal
list when content assist is requested. </li>
<li class="skipspace"><span>Specify the <b> <span class="uicontrol">Pattern</span></b> for your template using
the appropriate tags, attributes, or attribute values to be inserted by content
<li class="skipspace"><span>If you want to insert a variable in your <b>Pattern</b>, click the
<b> <span class="uicontrol">Insert Variable</span></b> button
and select the variable to be inserted. </span> For example, the<b> word_selection</b>
variable indicates the word that is selected at the beginning of template
insertion, and the <b>cursor</b> variable determines where the cursor will be after
the template is inserted in the HTML document.</li>
<li class="skipspace"><span>Click <b> <span class="uicontrol">Apply</span></b> and then
<b> <span class="uicontrol">OK</span></b> to
save your changes.</span></li>
<div class="skipspace">You can edit, remove, import, or export a template by using the same
preferences page. If you have modified a default template, you can restore
it to its default value. You can also restore a removed template if you have
not exited from the workbench since it was removed. <p>If you have a template
that you do not want to remove, but you no longer want the template to appear
in the content assist list, go to the <b>XML Templates </b>preferences page and
its check box.</p>
<div><div class="reltasks"><strong>Related tasks</strong><br />
<div><a href="../topics/txedtsrc.html" title="You can use the Source view to view and work with a file's source code directly.">Editing in the Source view</a></div>
<div><a href="../topics/twcdast.html" title="You can use content assist to help you finish a tag or line of code in the Source view of the XML editor. You can also use content assist to insert templates into your XML code.">Using XML content assist</a></div>