< prev index next >
src/java.xml.bind/share/classes/com/sun/xml/internal/txw2/output/XMLWriter.java
Print this page
*** 91,105 ****
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>
! * <?xml version="1.0" standalone="yes"?>
*
! * <greeting>Hello, world!</greeting>
! * </pre>
*
* <p>In fact, there is an even simpler convenience method,
* <var>dataElement</var>, designed for writing elements that
* contain only character data, so the code to generate the
* document could be shortened to</p>
--- 91,105 ----
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>{@code
! * <?xml version="1.0" standalone="yes"?>
*
! * <greeting>Hello, world!</greeting>
! * }</pre>
*
* <p>In fact, there is an even simpler convenience method,
* <var>dataElement</var>, designed for writing elements that
* contain only character data, so the code to generate the
* document could be shortened to</p>
*** 125,137 ****
* w.dataElement("item", "3");
* </pre>
*
* <p>you will end up with</p>
*
! * <pre>
! * <item>1</item><item>3</item><item>3</item>
! * </pre>
*
* <p>You need to invoke one of the <var>characters</var> methods
* explicitly to add newlines or indentation. Alternatively, you
* can use {@link DataWriter}, which
* is derived from this class -- it is optimized for writing
--- 125,137 ----
* w.dataElement("item", "3");
* </pre>
*
* <p>you will end up with</p>
*
! * <pre>{@code
! * <item>1</item><item>3</item><item>3</item>
! * }</pre>
*
* <p>You need to invoke one of the <var>characters</var> methods
* explicitly to add newlines or indentation. Alternatively, you
* can use {@link DataWriter}, which
* is derived from this class -- it is optimized for writing
*** 154,168 ****
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>
! * <?xml version="1.0" standalone="yes"?>
*
! * <_NS1:foo xmlns:_NS1="http://www.foo.com/ns/"/>
! * </pre>
*
* <p>In many cases, document authors will prefer to choose their
* own prefixes rather than using the (ugly) default names. The
* XML writer allows two methods for selecting prefixes:</p>
*
--- 154,168 ----
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>{@code
! * <?xml version="1.0" standalone="yes"?>
*
! * <_NS1:foo xmlns:_NS1="http://www.foo.com/ns/"/>
! * }</pre>
*
* <p>In many cases, document authors will prefer to choose their
* own prefixes rather than using the (ugly) default names. The
* XML writer allows two methods for selecting prefixes:</p>
*
*** 186,200 ****
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>
! * <?xml version="1.0" standalone="yes"?>
*
! * <foo:foo xmlns:foo="http://www.foo.com/ns/"/>
! * </pre>
*
* <p>The default Namespace simply uses an empty string as the prefix:</p>
*
* <pre>
* w.setPrefix("http://www.foo.com/ns/", "");
--- 186,200 ----
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>{@code
! * <?xml version="1.0" standalone="yes"?>
*
! * <foo:foo xmlns:foo="http://www.foo.com/ns/"/>
! * }</pre>
*
* <p>The default Namespace simply uses an empty string as the prefix:</p>
*
* <pre>
* w.setPrefix("http://www.foo.com/ns/", "");
*** 203,234 ****
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>
! * <?xml version="1.0" standalone="yes"?>
*
! * <foo xmlns="http://www.foo.com/ns/"/>
! * </pre>
*
* <p>By default, the XML writer will not declare a Namespace until
* it is actually used. Sometimes, this approach will create
* a large number of Namespace declarations, as in the following
* example:</p>
*
! * <pre>
! * <xml version="1.0" standalone="yes"?>
*
! * <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
! * <rdf:Description about="http://www.foo.com/ids/books/12345">
! * <dc:title xmlns:dc="http://www.purl.org/dc/">A Dark Night</dc:title>
! * <dc:creator xmlns:dc="http://www.purl.org/dc/">Jane Smith</dc:title>
! * <dc:date xmlns:dc="http://www.purl.org/dc/">2000-09-09</dc:title>
! * </rdf:Description>
! * </rdf:RDF>
! * </pre>
*
* <p>The "rdf" prefix is declared only once, because the RDF Namespace
* is used by the root element and can be inherited by all of its
* descendants; the "dc" prefix, on the other hand, is declared three
* times, because no higher element uses the Namespace. To solve this
--- 203,234 ----
* w.endDocument();
* </pre>
*
* <p>The resulting document will look like this:</p>
*
! * <pre>{@code
! * <?xml version="1.0" standalone="yes"?>
*
! * <foo xmlns="http://www.foo.com/ns/"/>
! * }</pre>
*
* <p>By default, the XML writer will not declare a Namespace until
* it is actually used. Sometimes, this approach will create
* a large number of Namespace declarations, as in the following
* example:</p>
*
! * <pre>{@code
! * <xml version="1.0" standalone="yes"?>
*
! * <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
! * <rdf:Description about="http://www.foo.com/ids/books/12345">
! * <dc:title xmlns:dc="http://www.purl.org/dc/">A Dark Night</dc:title>
! * <dc:creator xmlns:dc="http://www.purl.org/dc/">Jane Smith</dc:title>
! * <dc:date xmlns:dc="http://www.purl.org/dc/">2000-09-09</dc:title>
! * </rdf:Description>
! * </rdf:RDF>
! * }</pre>
*
* <p>The "rdf" prefix is declared only once, because the RDF Namespace
* is used by the root element and can be inherited by all of its
* descendants; the "dc" prefix, on the other hand, is declared three
* times, because no higher element uses the Namespace. To solve this
*** 241,262 ****
*
* <p>Now, the "dc" prefix will be declared on the root element even
* though it's not needed there, and can be inherited by its
* descendants:</p>
*
! * <pre>
! * <xml version="1.0" standalone="yes"?>
*
! * <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
* xmlns:dc="http://www.purl.org/dc/">
! * <rdf:Description about="http://www.foo.com/ids/books/12345">
! * <dc:title>A Dark Night</dc:title>
! * <dc:creator>Jane Smith</dc:title>
! * <dc:date>2000-09-09</dc:title>
! * </rdf:Description>
! * </rdf:RDF>
! * </pre>
*
* <p>This approach is also useful for declaring Namespace prefixes
* that be used by qualified names appearing in attribute values or
* character data.</p>
*
--- 241,262 ----
*
* <p>Now, the "dc" prefix will be declared on the root element even
* though it's not needed there, and can be inherited by its
* descendants:</p>
*
! * <pre>{@code
! * <xml version="1.0" standalone="yes"?>
*
! * <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
* xmlns:dc="http://www.purl.org/dc/">
! * <rdf:Description about="http://www.foo.com/ids/books/12345">
! * <dc:title>A Dark Night</dc:title>
! * <dc:creator>Jane Smith</dc:title>
! * <dc:date>2000-09-09</dc:title>
! * </rdf:Description>
! * </rdf:RDF>
! * }</pre>
*
* <p>This approach is also useful for declaring Namespace prefixes
* that be used by qualified names appearing in attribute values or
* character data.</p>
*
*** 386,396 ****
this.encoding = encoding;
}
/**
* Set whether the writer should print out the XML declaration
! * (<?xml version='1.0' ... ?>).
* <p>
* This option is set to true by default.
*/
public void setXmlDecl( boolean _writeXmlDecl ) {
this.writeXmlDecl = _writeXmlDecl;
--- 386,396 ----
this.encoding = encoding;
}
/**
* Set whether the writer should print out the XML declaration
! * ({@code <?xml version='1.0' ... ?>}).
* <p>
* This option is set to true by default.
*/
public void setXmlDecl( boolean _writeXmlDecl ) {
this.writeXmlDecl = _writeXmlDecl;
< prev index next >