blob: cb7331a2bfa3461c755a2d3f13c03aea3a469c73 [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 lang="en-us" xml:lang="en-us">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<meta name="copyright" content="Copyright (c) 2000, 2009 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v2.0 which accompanies this distribution, and is available at https://www.eclipse.org/legal/epl-2.0/. Contributors: IBM Corporation - initial API and implementation" />
<meta name="DC.rights.owner" content="(C) Copyright 2000, 2009" />
<meta content="public" name="security" />
<meta content="index,follow" name="Robots" />
<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))' />
<meta content="task" name="DC.Type" />
<meta name="DC.Title" content="Generating XML files from XML schemas" />
<meta name="abstract" content="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." />
<meta name="description" content="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." />
<meta content="XML files, generating from XML schemas, schemas, generating XML files, XML files" name="DC.subject" />
<meta content="XML files, generating from XML schemas, schemas, generating XML files, XML files" name="keywords" />
<meta scheme="URI" name="DC.Relation" content="../topics/tcretxml.html" />
<meta scheme="URI" name="DC.Relation" content="../topics/tcrexdtd.html" />
<meta scheme="URI" name="DC.Relation" content="../topics/txedttag.html" />
<meta scheme="URI" name="DC.Relation" content="../topics/cwxmledt.html" />
<meta scheme="URI" name="DC.Relation" content="../../org.eclipse.wst.xsdeditor.doc.user/topics/rnmspc.html" />
<meta content="XHTML" name="DC.Format" />
<meta content="tcrexxsd" name="DC.Identifier" />
<meta content="en-us" name="DC.Language" />
<link href="../../org.eclipse.wst.doc.user/common.css" type="text/css" rel="stylesheet" />
<title>Generating an XML file from an XML schema</title>
</head>
<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 perspectives.</p>
<p>To
generate an XML file from a schema file follow these steps:</p>
</div>
<ol>
<li class="stepexpand"><span>In the Navigator view, right-click the XML schema file that you
want to work with and select <span class="menucascade"><span class="uicontrol">Generate</span>
&gt; <span class="uicontrol">XML File</span></span>.</span></li>
<li class="stepexpand"><span>Select a project or folder to contain the XML file and type a name
for the file in the <span class="uicontrol">File Name</span> field, then click <span class="uicontrol">Next</span>.</span>
The name of the file must end in <kbd class="userinput">.xml</kbd>.
</li>
<li class="stepexpand"><span>Select the <span class="uicontrol">Root element</span> 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 Root element list. If you do not have any
global elements in your XML schema, you cannot create an XML file from it.
</li>
<li class="stepexpand"><span>Select from the following content options:</span>
<ul>
<li><span class="uicontrol">Create optional attributes</span>: both mandatory
and optional attributes will be generated.</li>
<li><span class="uicontrol">Create optional elements</span>: both mandatory and
optional elements will be generated.</li>
<li><span class="uicontrol">Create first choice of required choice</span>: the
first option of a required choice will be generated in your XML file.</li>
<li><span class="uicontrol">Fill elements and attributes with data</span>: any
elements and attributes generated will be filled with sample data.</li>
</ul>
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="stepexpand"><span>The Namespace Information section contains information about the
target namespace of the XML schema, its prefix, and the schema location. Select
the entry you want to edit and click <span class="uicontrol">Edit</span>.</span> <ul>
<li>The value in the <span class="uicontrol">Namespace Name</span> field is the target
namespace of the XML schema. Your XML file should be associated with the same
namespace as its XML schema is associated with.</li>
<li>All qualified elements and attributes in the XML file associated with
the namespace will be prefixed with the <span class="uicontrol">Prefix</span> value.</li>
<li>The <span class="uicontrol">Location Hint</span> field contains the location
of the XML schema.</li>
</ul>
For more information about namespaces and namespace prefixes, refer to
the related references.</li>
<li class="stepexpand"><span>Click <span class="uicontrol">OK</span> and then <span class="uicontrol">Finish</span>.</span>
</li>
</ol>
<div class="section"><p>The 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>
<div class="note"><span class="notetitle">Note:</span> In certain cases, when an XML file is generated
from a complex XML schema file, the XML file might 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 might present problems:</div>
<ul>
<li>Restrictions: sometimes restricted elements are erroneously generated. </li>
<li>Facets: default generated data values might not conform to complex facets
(for example, patterns).</li>
<li>Abstract elements: abstract elements are sometimes erroneously generated.</li>
</ul>
</div>
</div>
<div><div class="relconcepts"><strong>Related concepts</strong><br />
<div><a href="../topics/cwxmledt.html" title="The XML editor is a tool for creating and viewing XML files.">XML editor</a></div>
</div>
<div class="reltasks"><strong>Related tasks</strong><br />
<div><a href="../topics/tcretxml.html" title="You can create a new XML file which you can then edit in the XML editor. You create a new XML file that is not associated with a DTD or XML schema file, so there are no restrictions on the kind of content it can contain.">Creating XML files</a></div>
<div><a href="../topics/tcrexdtd.html" title="You can generate an XML file from your DTD if you want to quickly create an XML file based on your DTD file. Generating an XML file from your DTD saves you time by creating an XML file that is already associated with your DTD, and contains at least some of the elements and attributes in your DTD.">Generating XML files from DTDs</a></div>
<div><a href="../topics/txedttag.html" title="This file contains information about editing XML files.">Editing XML files</a></div>
</div>
<div class="relinfo"><strong>Related information</strong><br />
<div><a href="../../org.eclipse.wst.xsdeditor.doc.user/topics/rnmspc.html">XML namespaces</a></div>
</div>
</div>
</body>
</html>