jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/txw2/output/XMLWriter.java
changeset 32795 5a5710ee05a0
parent 25871 b80b84e87032
child 33547 e4c76ac38b12
equal deleted inserted replaced
32712:f61a63b7d1e5 32795:5a5710ee05a0
    91  * w.endDocument();
    91  * w.endDocument();
    92  * </pre>
    92  * </pre>
    93  *
    93  *
    94  * <p>The resulting document will look like this:</p>
    94  * <p>The resulting document will look like this:</p>
    95  *
    95  *
    96  * <pre>
    96  * <pre>{@code
    97  * &lt;?xml version="1.0" standalone="yes"?>
    97  * <?xml version="1.0" standalone="yes"?>
    98  *
    98  *
    99  * &lt;greeting>Hello, world!&lt;/greeting>
    99  * <greeting>Hello, world!</greeting>
   100  * </pre>
   100  * }</pre>
   101  *
   101  *
   102  * <p>In fact, there is an even simpler convenience method,
   102  * <p>In fact, there is an even simpler convenience method,
   103  * <var>dataElement</var>, designed for writing elements that
   103  * <var>dataElement</var>, designed for writing elements that
   104  * contain only character data, so the code to generate the
   104  * contain only character data, so the code to generate the
   105  * document could be shortened to</p>
   105  * document could be shortened to</p>
   125  * w.dataElement("item", "3");
   125  * w.dataElement("item", "3");
   126  * </pre>
   126  * </pre>
   127  *
   127  *
   128  * <p>you will end up with</p>
   128  * <p>you will end up with</p>
   129  *
   129  *
   130  * <pre>
   130  * <pre>{@code
   131  * &lt;item>1&lt;/item>&lt;item>3&lt;/item>&lt;item>3&lt;/item>
   131  * <item>1</item><item>3</item><item>3</item>
   132  * </pre>
   132  * }</pre>
   133  *
   133  *
   134  * <p>You need to invoke one of the <var>characters</var> methods
   134  * <p>You need to invoke one of the <var>characters</var> methods
   135  * explicitly to add newlines or indentation.  Alternatively, you
   135  * explicitly to add newlines or indentation.  Alternatively, you
   136  * can use {@link DataWriter}, which
   136  * can use {@link DataWriter}, which
   137  * is derived from this class -- it is optimized for writing
   137  * is derived from this class -- it is optimized for writing
   154  * w.endDocument();
   154  * w.endDocument();
   155  * </pre>
   155  * </pre>
   156  *
   156  *
   157  * <p>The resulting document will look like this:</p>
   157  * <p>The resulting document will look like this:</p>
   158  *
   158  *
   159  * <pre>
   159  * <pre>{@code
   160  * &lt;?xml version="1.0" standalone="yes"?>
   160  * <?xml version="1.0" standalone="yes"?>
   161  *
   161  *
   162  * &lt;_NS1:foo xmlns:_NS1="http://www.foo.com/ns/"/>
   162  * <_NS1:foo xmlns:_NS1="http://www.foo.com/ns/"/>
   163  * </pre>
   163  * }</pre>
   164  *
   164  *
   165  * <p>In many cases, document authors will prefer to choose their
   165  * <p>In many cases, document authors will prefer to choose their
   166  * own prefixes rather than using the (ugly) default names.  The
   166  * own prefixes rather than using the (ugly) default names.  The
   167  * XML writer allows two methods for selecting prefixes:</p>
   167  * XML writer allows two methods for selecting prefixes:</p>
   168  *
   168  *
   186  * w.endDocument();
   186  * w.endDocument();
   187  * </pre>
   187  * </pre>
   188  *
   188  *
   189  * <p>The resulting document will look like this:</p>
   189  * <p>The resulting document will look like this:</p>
   190  *
   190  *
   191  * <pre>
   191  * <pre>{@code
   192  * &lt;?xml version="1.0" standalone="yes"?>
   192  * <?xml version="1.0" standalone="yes"?>
   193  *
   193  *
   194  * &lt;foo:foo xmlns:foo="http://www.foo.com/ns/"/>
   194  * <foo:foo xmlns:foo="http://www.foo.com/ns/"/>
   195  * </pre>
   195  * }</pre>
   196  *
   196  *
   197  * <p>The default Namespace simply uses an empty string as the prefix:</p>
   197  * <p>The default Namespace simply uses an empty string as the prefix:</p>
   198  *
   198  *
   199  * <pre>
   199  * <pre>
   200  * w.setPrefix("http://www.foo.com/ns/", "");
   200  * w.setPrefix("http://www.foo.com/ns/", "");
   203  * w.endDocument();
   203  * w.endDocument();
   204  * </pre>
   204  * </pre>
   205  *
   205  *
   206  * <p>The resulting document will look like this:</p>
   206  * <p>The resulting document will look like this:</p>
   207  *
   207  *
   208  * <pre>
   208  * <pre>{@code
   209  * &lt;?xml version="1.0" standalone="yes"?>
   209  * <?xml version="1.0" standalone="yes"?>
   210  *
   210  *
   211  * &lt;foo xmlns="http://www.foo.com/ns/"/>
   211  * <foo xmlns="http://www.foo.com/ns/"/>
   212  * </pre>
   212  * }</pre>
   213  *
   213  *
   214  * <p>By default, the XML writer will not declare a Namespace until
   214  * <p>By default, the XML writer will not declare a Namespace until
   215  * it is actually used.  Sometimes, this approach will create
   215  * it is actually used.  Sometimes, this approach will create
   216  * a large number of Namespace declarations, as in the following
   216  * a large number of Namespace declarations, as in the following
   217  * example:</p>
   217  * example:</p>
   218  *
   218  *
   219  * <pre>
   219  * <pre>{@code
   220  * &lt;xml version="1.0" standalone="yes"?>
   220  * <xml version="1.0" standalone="yes"?>
   221  *
   221  *
   222  * &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   222  * <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
   223  *  &lt;rdf:Description about="http://www.foo.com/ids/books/12345">
   223  *  <rdf:Description about="http://www.foo.com/ids/books/12345">
   224  *   &lt;dc:title xmlns:dc="http://www.purl.org/dc/">A Dark Night&lt;/dc:title>
   224  *   <dc:title xmlns:dc="http://www.purl.org/dc/">A Dark Night</dc:title>
   225  *   &lt;dc:creator xmlns:dc="http://www.purl.org/dc/">Jane Smith&lt;/dc:title>
   225  *   <dc:creator xmlns:dc="http://www.purl.org/dc/">Jane Smith</dc:title>
   226  *   &lt;dc:date xmlns:dc="http://www.purl.org/dc/">2000-09-09&lt;/dc:title>
   226  *   <dc:date xmlns:dc="http://www.purl.org/dc/">2000-09-09</dc:title>
   227  *  &lt;/rdf:Description>
   227  *  </rdf:Description>
   228  * &lt;/rdf:RDF>
   228  * </rdf:RDF>
   229  * </pre>
   229  * }</pre>
   230  *
   230  *
   231  * <p>The "rdf" prefix is declared only once, because the RDF Namespace
   231  * <p>The "rdf" prefix is declared only once, because the RDF Namespace
   232  * is used by the root element and can be inherited by all of its
   232  * is used by the root element and can be inherited by all of its
   233  * descendants; the "dc" prefix, on the other hand, is declared three
   233  * descendants; the "dc" prefix, on the other hand, is declared three
   234  * times, because no higher element uses the Namespace.  To solve this
   234  * times, because no higher element uses the Namespace.  To solve this
   241  *
   241  *
   242  * <p>Now, the "dc" prefix will be declared on the root element even
   242  * <p>Now, the "dc" prefix will be declared on the root element even
   243  * though it's not needed there, and can be inherited by its
   243  * though it's not needed there, and can be inherited by its
   244  * descendants:</p>
   244  * descendants:</p>
   245  *
   245  *
   246  * <pre>
   246  * <pre>{@code
   247  * &lt;xml version="1.0" standalone="yes"?>
   247  * <xml version="1.0" standalone="yes"?>
   248  *
   248  *
   249  * &lt;rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   249  * <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   250  *             xmlns:dc="http://www.purl.org/dc/">
   250  *             xmlns:dc="http://www.purl.org/dc/">
   251  *  &lt;rdf:Description about="http://www.foo.com/ids/books/12345">
   251  *  <rdf:Description about="http://www.foo.com/ids/books/12345">
   252  *   &lt;dc:title>A Dark Night&lt;/dc:title>
   252  *   <dc:title>A Dark Night</dc:title>
   253  *   &lt;dc:creator>Jane Smith&lt;/dc:title>
   253  *   <dc:creator>Jane Smith</dc:title>
   254  *   &lt;dc:date>2000-09-09&lt;/dc:title>
   254  *   <dc:date>2000-09-09</dc:title>
   255  *  &lt;/rdf:Description>
   255  *  </rdf:Description>
   256  * &lt;/rdf:RDF>
   256  * </rdf:RDF>
   257  * </pre>
   257  * }</pre>
   258  *
   258  *
   259  * <p>This approach is also useful for declaring Namespace prefixes
   259  * <p>This approach is also useful for declaring Namespace prefixes
   260  * that be used by qualified names appearing in attribute values or
   260  * that be used by qualified names appearing in attribute values or
   261  * character data.</p>
   261  * character data.</p>
   262  *
   262  *
   386         this.encoding = encoding;
   386         this.encoding = encoding;
   387     }
   387     }
   388 
   388 
   389     /**
   389     /**
   390      * Set whether the writer should print out the XML declaration
   390      * Set whether the writer should print out the XML declaration
   391      * (&lt;?xml version='1.0' ... ?>).
   391      * ({@code <?xml version='1.0' ... ?>}).
   392      * <p>
   392      * <p>
   393      * This option is set to true by default.
   393      * This option is set to true by default.
   394      */
   394      */
   395     public void setXmlDecl( boolean _writeXmlDecl ) {
   395     public void setXmlDecl( boolean _writeXmlDecl ) {
   396         this.writeXmlDecl = _writeXmlDecl;
   396         this.writeXmlDecl = _writeXmlDecl;