xml.schema/javahelp/org/netbeans/modules/xml/schema/tasks/usingcodecompletion-oneschema.html
author Milutin Kristofic <mkristofic@netbeans.org>
Tue, 31 Jan 2017 14:20:36 +0100
changeset 1584 ddcac47bfed1
parent 1241 f7c3471c4a3f
permissions -rw-r--r--
Added Missing license terms
samaresh@338
     1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
samaresh@338
     2
<!--
mkristofic@1584
     3
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
mkristofic@1584
     4
mkristofic@1584
     5
Copyright 2009-2017 Oracle and/or its affiliates. All rights reserved.
mkristofic@1584
     6
mkristofic@1584
     7
Oracle and Java are registered trademarks of Oracle and/or its affiliates.
mkristofic@1584
     8
Other names may be trademarks of their respective owners.
mkristofic@1584
     9
mkristofic@1584
    10
The contents of this file are subject to the terms of either the GNU
mkristofic@1584
    11
General Public License Version 2 only ("GPL") or the Common
mkristofic@1584
    12
Development and Distribution License("CDDL") (collectively, the
mkristofic@1584
    13
"License"). You may not use this file except in compliance with the
mkristofic@1584
    14
License. You can obtain a copy of the License at
mkristofic@1584
    15
http://www.netbeans.org/cddl-gplv2.html
mkristofic@1584
    16
or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
mkristofic@1584
    17
specific language governing permissions and limitations under the
mkristofic@1584
    18
License.  When distributing the software, include this License Header
mkristofic@1584
    19
Notice in each file and include the License file at
mkristofic@1584
    20
nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
mkristofic@1584
    21
particular file as subject to the "Classpath" exception as provided
mkristofic@1584
    22
by Oracle in the GPL Version 2 section of the License file that
mkristofic@1584
    23
accompanied this code. If applicable, add the following below the
mkristofic@1584
    24
License Header, with the fields enclosed by brackets [] replaced by
mkristofic@1584
    25
your own identifying information:
mkristofic@1584
    26
"Portions Copyrighted [year] [name of copyright owner]"
mkristofic@1584
    27
mkristofic@1584
    28
Contributor(s):
mkristofic@1584
    29
mkristofic@1584
    30
The Original Software is NetBeans. The Initial Developer of the Original
mkristofic@1584
    31
Software is Sun Microsystems, Inc. Portions Copyright 2009-2010 Sun
mkristofic@1584
    32
Microsystems, Inc. All Rights Reserved.
mkristofic@1584
    33
mkristofic@1584
    34
If you wish your version of this file to be governed by only the CDDL
mkristofic@1584
    35
or only the GPL Version 2, indicate your decision by adding
mkristofic@1584
    36
"[Contributor] elects to include this software in this distribution
mkristofic@1584
    37
under the [CDDL or GPL Version 2] license." If you do not indicate a
mkristofic@1584
    38
single choice of license, a recipient has the option to distribute
mkristofic@1584
    39
your version of this file under either the CDDL, the GPL Version 2 or
mkristofic@1584
    40
to extend the choice of license to its licensees as provided above.
mkristofic@1584
    41
However, if you add GPL Version 2 code and therefore, elected the GPL
mkristofic@1584
    42
Version 2 license, then the option applies only if the new code is
mkristofic@1584
    43
made subject to such option by the copyright holder.
samaresh@338
    44
-->
samaresh@338
    45
<html>
samaresh@338
    46
<head>
psmejkal@1107
    47
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
samaresh@338
    48
<link rel="stylesheet" href="nbdocs://org.netbeans.modules.usersguide/org/netbeans/modules/usersguide/ide.css" type="text/css">
jeff_rubinoff@808
    49
<title>Using Code Completion in XML Documents Constrained by a Single XML Schema</title>
samaresh@338
    50
</head>
samaresh@338
    51
<body>
jeff_rubinoff@808
    52
<h2>Using Code Completion in XML Documents Constrained by a Single XML Schema</h2>
samaresh@338
    53
<p><small><a href="#seealso">See Also</a></small></p>
samaresh@338
    54
<p>You can use code completion in XML files if the XML document is constrained by an XML schema. In the XML instance document, this constraint is represented by a <tt>xsi:schemaLocation</tt> or a <tt>xsi:noNamespaceSchemaLocation</tt> attribute in the root element of the schema. Typically, <tt>xsi:schemaLocation</tt> is used for schemas with a target namespace and <tt>xsi:noNamespaceSchemaLocation</tt> is used for schemas with no target namespace.</p>
jeff_rubinoff@808
    55
samaresh@338
    56
<p><b>To create an XML document constrained by an XML schema and invoke code completion:</b></p>
samaresh@338
    57
<ol>
samaresh@338
    58
<li>From the main menu, choose File &gt; New File.<br>
samaresh@338
    59
The New File wizard opens.</li>
samaresh@338
    60
<li>Under Categories, select the <tt>XML</tt> node and under File Types, select the <tt>XML Document</tt> node, then click Next.</li>
samaresh@338
    61
<li>Specify a name and location for the document and click Next.</li>
samaresh@338
    62
<li>Select the XML Schema-Constrained Document radio button and click Next.</li>
samaresh@338
    63
<li>Click the Browse button next to the Schema URI field to navigate to and select the schema file that will constrain the XML instance document.<br>
samaresh@338
    64
When you have selected the schema file, the IDE fills in the Document Namespace and Root Element fields. If the schema has no target namespace, the Document Namespace field is blank.</li>
samaresh@338
    65
<li>If the schema has more than one root element, select the element you want to use for the constraint from the Root Element drop-down list.</li>
samaresh@338
    66
<li>Click Finish.<br>
samaresh@338
    67
The IDE adds a node for the new <tt>.xml</tt> file in the Projects window, and the new file is open in the Source Editor.</li>
samaresh@338
    68
<li>In the Source Editor tab of the XML document, position the cursor where you want to start adding content and type an opening left angle bracket (<tt>&lt;</tt>).<br>
samaresh@338
    69
The code completion box opens. This box provides a scrolling list of schema elements. The list of elements is based on the XML schema file that constrains the current XML file.</li>
samaresh@338
    70
</ol>
samaresh@338
    71
samaresh@338
    72
<p><b>To constrain an existing XML document by an XML schema and invoke code completion:</b></p>
samaresh@338
    73
<ol>
samaresh@338
    74
<li>Make a note of the following information from the schema file:<br>
samaresh@338
    75
<ul>
samaresh@338
    76
<li>The <tt>targetNamespace</tt> value (<tt><i>schema-targetNamespace</i></tt>)</li>
samaresh@338
    77
<li>The root or top-level element that you want to use for the constraint (<tt><i>schema-root-element</i></tt>)</li>
samaresh@338
    78
</ul></li>
samaresh@338
    79
<li>Open the XML document in the Source Editor.</li>
samaresh@338
    80
<li>In the XML document, replace the <tt>&lt;root&gt;</tt> tag with the following tag:<br>
samaresh@338
    81
<pre>
samaresh@338
    82
&lt;<i>schema-root-element</i>
samaresh@338
    83
  xmlns='<i>schema-targetNamespace</i>'
samaresh@338
    84
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
samaresh@338
    85
  xsi:schemaLocation='<i>schema-targetNamespace</i> <i>path-to-schema</i>/<i>schema</i>.xsd'&gt;
samaresh@338
    86
</pre><br>
samaresh@338
    87
If the schema has no <tt>targetNamespace</tt>, use the following tag:
samaresh@338
    88
<pre>
samaresh@338
    89
&lt;<i>schema-root-element</i>
samaresh@338
    90
  xmlns:<i>prefix</i>='<i>schema-targetNamespace</i>'
samaresh@338
    91
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
samaresh@338
    92
  xsi:noNamespaceSchemaLocation='<i>path-to-schema</i>/<i>schema</i>.xsd'&gt;
samaresh@338
    93
</pre></li>
samaresh@338
    94
<li>Replace the <tt>&lt;/root&gt;</tt> tag with the following:<br>
samaresh@338
    95
<pre>
samaresh@338
    96
&lt;/<i>schema-root-element</i>&gt;
samaresh@338
    97
</pre></li>
samaresh@338
    98
<li>Save your changes.</li>
samaresh@338
    99
<li>In the Source Editor tab of the XML document, position the cursor where you want to start adding content and type an opening left angle bracket (<tt>&lt;</tt>).<br>
samaresh@338
   100
The code completion box opens. This box provides a scrolling list of schema elements. The list of elements is based on the XML schema file that constrains the current XML file.</li>
samaresh@338
   101
</ol>
samaresh@338
   102
samaresh@338
   103
<dl>
samaresh@338
   104
<dt><a name="seealso">See Also</a></dt>
samaresh@338
   105
<dd><a href="usingcodecompletion.html" title="About Using Code Completion in XML Instance Documents Constrained by XML Schema">About Using Code Completion in XML Instance Documents Constrained by XML Schema</a></dd>
samaresh@338
   106
<dd><a href="../about.html" title="About XML Schema Tools">About XML Schema Tools</a></dd>
samaresh@338
   107
</dl>
samaresh@338
   108
<hr>
samaresh@338
   109
<small><a href="../credits.html">Legal Notices</a></small>
samaresh@338
   110
<table cellpadding="150" border="0"> 
samaresh@338
   111
<tr><td>&nbsp;</td></tr> 
samaresh@338
   112
<tr><td>&nbsp;</td></tr> 
samaresh@338
   113
<tr><td>&nbsp;</td></tr> 
samaresh@338
   114
</table> 
samaresh@338
   115
</body>
samaresh@338
   116
</html>
samaresh@338
   117