Java Reference
In-Depth Information
void setPrefix(String prefix, String uri) identifies the
namespace prefix to which the uri value is bound. This prefix is used
by variants of the writeStartElement() , writeAttribute() , and
writeEmptyElement() methods that take namespace arguments but not
prefixes. Also, it remains valid until the writeEndElement() invocation
thatcorrespondstothelast writeStartElement() invocation.Thismeth-
od does not create any output.
void writeAttribute(String localName, String value)
writestheattributeidentifiedby localName andhavingthespecified value
to the underlying writer. A namespace prefix isn't included. This method es-
capes & , < and > , and " .
void writeCharacters(String text) writes text 's characters to
the underlying writer. This method escapes & , <, and > .
void writeEndDocument() closesanystarttagsandwritescorrespond-
ing end tags to the underlying writer.
void endElement() writesanendtagtotheunderlyingwriter,relyingon
the internal state of the stream-based writer to determine the tag's prefix and
local name.
void writeNamespace(String prefix, String
namespaceURI) writes a namespace to the underlying writer. This method
mustbecalled toensurethatthenamespace specified by setPrefix() and
duplicatedinthismethodcalliswritten;otherwise,theresultingdocumentwill
not be well formed from a namespace perspective.
void writeStartDocument() writestheXMLdeclarationtotheunder-
lying writer.
void writeStartElement(String namespaceURI, String
localName) writesastarttagwiththeargumentspassedto namespaceURI
and localName to the underlying writer.
Listing10-18 presentsthesourcecodetoa StAXDemo applicationthatcreatesa re-
cipe.xml file with many of Listing 10-5 's infoset items via a stream-based writer.
Listing 10-18. StAXDemo (version 3)
import java.io.FileWriter;
import java.io.IOException;
Search WWH ::




Custom Search