blob: 1bb9af085118d595d6bd11aa5458aeaebab8e740 [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>Generating an XML file from an XML schema</title>
<body id="tcrexxsd"><a name="tcrexxsd"><!-- --></a>
<h1 class="topictitle1">Generating XML files from XML schemas</h1>
<div><p>You can generate an XML file from your XML schema if you want to
quickly create an XML file based on your XML schema file. Generating an XML
file from your XML schema saves you time by creating an XML file that is already
associated with your XML schema, and contains at least some of the elements
and attributes in your XML schema.</p>
<div class="section"><p>After you have generated your XML file, you can further customize
it in the XML editor.</p>
<p>The following instructions were
written for the Resource perspective, but they will also work in many other
<p>To generate an XML file from a schema file follow these
<ol><li class="skipspace"><span>In the Navigator view, right-click the XML schema file that you
want to work with.</span></li>
<li class="skipspace"><span>From its pop-up menu click <b> <span class="menucascade"><span class="uicontrol">Generate</span> &gt; <span class="uicontrol">XML File</span></span></b>.</span></li>
<li class="skipspace"><span>Select a project or folder to contain the XML file and type a name
for it.</span> The name of the file must end in<tt class="sysout">.xml.</tt> </li>
<li class="skipspace"><span>Click <b> <span class="uicontrol">Next</span></b>.</span></li>
<li class="skipspace"><span>Click the <b> <span class="uicontrol">Root element</span>
</b>of the XML file.</span> The root element of an XML file is the element that contains all other
elements in that file. All of the global elements you have defined in the
XML schema will be included in the <b>Root Element </b>list. If you do not have any
global elements in your XML schema, you cannot create an XML file from it.</li>
<li class="skipspace"><span>Select from the following content options: </span><ul><li>
<b><span class="uicontrol">Create optional attributes</span> </b>- Both mandatory
and optional attributes will be generated</li>
<li><b><span class="uicontrol">Create optional elements</span> </b>- Both mandatory and
optional elements will be generated.</li>
<li><b><span class="uicontrol">Create first choice of required choice</span></b> -
The first option of a required choice will be generated in your XML file.</li>
<li><b><span class="uicontrol">Fill elements and attributes with data</span> </b>- any
elements and attributes generated will be filled with sample data.</li>
If you do not select any of these options, then only the minimum amount
of content required for the XML file will be created.</li>
<li class="skipspace"><span>The <b>Namespace</b> <b>information</b> section contains information about the
target namespace of the XML schema, its prefix, and the schema location.</span>
For more information about namespaces and namespace prefixes, refer to the
Related reference below.</li>
<li class="skipspace"><span>Select the entry you want to edit and click <b> <span class="uicontrol">Edit</span></b>.</span></li>
<li class="skipspace"><span>The value in the <b> <span class="uicontrol">Namespace Name</span>
</b>field is
the target namespace of the XML schema.</span> Your XML file should be
associated with the same namespace as its XML schema is associated with.</li>
<li class="skipspace"><span>All qualified elements and attributes in the XML file associated
with the namespace will be prefixed with the <b> <span class="uicontrol">Prefix</span></b> value.</span></li>
<li class="skipspace"><span>The <b> <span class="uicontrol">Location Hint</span>
</b>field contains the location
of the XML schema.</span></li>
<li class="skipspace"><span>Click <b> <span class="uicontrol">OK</span></b>, then
<b> <span class="uicontrol">Finish</span></b>.</span></li>
<div class="skipspace">
XML file will contain the selected root element and any elements or attributes
contained in the root element. It also contains information about the XML
file namespace and location. You can now add elements and attributes to the
XML file.</p>
<p><b>Note:</b> In certain cases, when an XML file is generated
from a complex XML schema file, the XML file may not be valid. If this occurs,
you can open the generated file in the XML editor and correct any errors that
occur. Usually, only a few errors need to be fixed. The following XML schema
constructs may present problems:</p>
<ol><li>Restrictions. Sometimes restricted elements are erroneously generated. </li>
<li>Facets: Default generated data values may not conform to complex facets
(for example, patterns).</li>
<li> Abstract elements. abstract elements are sometimes erroneously generated.</li>
<div><p><b class="relconceptshd">Related concepts</b><br />
<a href="../topics/cwxmledt.html" title="The XML editor is a tool for creating and viewing XML files">XML editor</a><br />
<p><b class="reltaskshd">Related tasks</b><br />
<a href="../topics/tcretxml.html" title="You can create a new empty XML file, which you can then edit in the XML editor.">Creating an XML file from scratch</a><br />
<a href="../topics/tcrexdtd.html" title="Generating an XML file from a DTD">Generating an XML file from a DTD</a><br />
<a href="../topics/txedttag.html" title="Editing XML files">Editing XML files</a><br />
<p><b class="reltaskshd">Related references</b><br />
<a href="../../org.eclipse.wst.xsdeditor.doc.user/topics/rnmspc.html">XML
namespaces</a><br />