Package gnu.xml
Class XMLPrinter
java.lang.Object
java.io.Writer
java.io.PrintWriter
gnu.lists.PrintConsumer
gnu.xml.XMLPrinter
- All Implemented Interfaces:
Consumer,PositionConsumer,XConsumer,Closeable,Flushable,Appendable,AutoCloseable,Consumer<Object>,DoubleConsumer,IntConsumer,LongConsumer
Print an event stream in XML format on a PrintWriter.
-
Field Summary
FieldsModifier and TypeFieldDescriptionbooleanstatic final ThreadLocationThe system identifier emitted in a DOCTYPE declaration.static final ThreadLocationFluid parameter to control whether a DOCTYPE declaration is emitted.booleanbooleanbooleanbooleanWhen indenting, should attributes be lined up?static final ThreadLocation<String> protected intintHandling of empty elements.Fields inherited from class gnu.lists.PrintConsumer
base, skippingFields inherited from class java.io.PrintWriter
out -
Constructor Summary
ConstructorsConstructorDescriptionXMLPrinter(Consumer out) XMLPrinter(PrintConsumer out) XMLPrinter(OutputStream out) XMLPrinter(Writer out) XMLPrinter(Writer out, boolean autoFlush) -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidbeginEntity(Object base) voidcloseTag()voidEnd of an attribute or end of an actual parameter.voidvoidvoidvoidprotected voidvoidstatic StringformatDecimal(BigDecimal dec) Format java.math.BigDecimal as needed for XPath/XQuery's xs:decimal.static StringformatDouble(double d) Helper to format xs:double according to XPath/XQuery specification.static StringformatFloat(float f) Helper to format xs:float according to XPath/XQuery specification.protected StringgetHtmlTag(Object type) booleanignoring()True if consumer is ignoring rest of element.static booleanisHtmlEmptyElementTag(String name) static XMLPrintervoidvoidsetCanonicalizeCDATA(boolean v) voidsetEscapeNonAscii(boolean v) voidsetEscapeText(boolean v) voidsetExtended(boolean v) voidsetIndent(int v) Controls whether to add extra indentation.voidsetPrintXMLdecl(boolean value) voidvoidsetUseEmptyElementTag(int v) voidstartAttribute(Object attrType) Write a attribute for the current element.voidvoidstartElement(Object type) protected voidstatic StringConvert argument to string in XML syntax.voidwrite(char[] buf, int off, int len) voidwrite(int v) voidvoidwriteBaseUri(Object uri) voidwriteBoolean(boolean v) voidwriteCDATA(char[] chars, int offset, int length) voidwriteComment(char[] chars, int offset, int length) voidwriteComment(String chars) voidwriteDoctype(String tagname, String systemId, String publicId) voidwriteDoctypeIfDefined(String tagname) Write DOCTYPE using ThreadLocations doctypeSystem and doctypePublicvoidwriteDouble(double d) voidwriteFloat(float f) voidvoidwritePosition(AbstractSequence seq, int ipos) Consume a single position pair.voidwritePosition(SeqPosition position) Consume node at current position.voidwriteProcessingInstruction(String target, char[] content, int offset, int length) protected voidwriteQName(Object name) Methods inherited from class gnu.lists.PrintConsumer
append, append, append, beforeContent, beforeNode, clearWordEnd, endHiderSection, endLogicalBlock, endLogicalBlock, freshLine, getPrettyWriter, isDomTerm, setIndentation, startHiderSection, startLogicalBlock, startLogicalBlock, startLogicalBlock, write, writeBreak, writeBreakFill, writeBreakFill, writeBreakLinear, writeInt, writeLong, writeRaw, writeRaw, writeRaw, writeRaw, writeShowHideButton, writeSpace, writeSpaceFill, writeSpaceFill, writeSpaceLinear, writeWordEnd, writeWordStartMethods inherited from class java.io.PrintWriter
checkError, clearError, close, flush, format, format, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, writeMethods inherited from class java.io.Writer
nullWriterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface gnu.lists.Consumer
accept, accept, accept, accept, append, append, append, write, write, writeInt, writeLongMethods inherited from interface java.util.function.DoubleConsumer
andThenMethods inherited from interface java.util.function.IntConsumer
andThenMethods inherited from interface java.util.function.LongConsumer
andThen
-
Field Details
-
printIndent
protected int printIndent -
indentAttributes
public boolean indentAttributesWhen indenting, should attributes be lined up? -
canonicalizeCDATA
public boolean canonicalizeCDATA -
useEmptyElementTag
public int useEmptyElementTagHandling of empty elements. 0: No element element tags, as required for canonical XML:<br></br>. 1: Use XML-style empty element tags:<br/>2: Use HTML-compatible empty element tags:<br />but<p></p>. -
escapeText
public boolean escapeText -
escapeNonAscii
public boolean escapeNonAscii -
extended
public boolean extended -
doctypeSystem
Fluid parameter to control whether a DOCTYPE declaration is emitted. If non-null, this is the the public identifier. -
doctypePublic
The system identifier emitted in a DOCTYPE declaration. Has no effect if doctypeSystem returns null. If non-null, this is the the system identifier. -
indentLoc
-
-
Constructor Details
-
XMLPrinter
-
XMLPrinter
-
XMLPrinter
-
XMLPrinter
-
XMLPrinter
-
-
Method Details
-
setPrintXMLdecl
public void setPrintXMLdecl(boolean value) -
make
-
toString
Convert argument to string in XML syntax. -
setStyle
-
setEscapeText
public void setEscapeText(boolean v) -
setEscapeNonAscii
public void setEscapeNonAscii(boolean v) -
setCanonicalizeCDATA
public void setCanonicalizeCDATA(boolean v) -
setUseEmptyElementTag
public void setUseEmptyElementTag(int v) -
setExtended
public void setExtended(boolean v) -
setIndent
public void setIndent(int v) Controls whether to add extra indentation. -1: don't add indentation; 0: pretty-print (avoid needless newlines); 1: indent (force). -
write
public void write(int v) - Specified by:
writein interfaceConsumer- Overrides:
writein classPrintWriter
-
writeBoolean
public void writeBoolean(boolean v) - Specified by:
writeBooleanin interfaceConsumer- Overrides:
writeBooleanin classPrintConsumer
-
startNumber
protected void startNumber()- Overrides:
startNumberin classPrintConsumer
-
endNumber
protected void endNumber()- Overrides:
endNumberin classPrintConsumer
-
closeTag
public void closeTag() -
startDocument
public void startDocument()- Specified by:
startDocumentin interfaceConsumer- Overrides:
startDocumentin classPrintConsumer
-
endDocument
public void endDocument()- Specified by:
endDocumentin interfaceConsumer- Overrides:
endDocumentin classPrintConsumer
-
beginEntity
- Specified by:
beginEntityin interfaceXConsumer- Overrides:
beginEntityin classPrintConsumer
-
endEntity
public void endEntity()- Specified by:
endEntityin interfaceXConsumer- Overrides:
endEntityin classPrintConsumer
-
writeQName
-
writeDoctypeIfDefined
Write DOCTYPE using ThreadLocations doctypeSystem and doctypePublic -
writeDoctype
-
startElement
- Specified by:
startElementin interfaceConsumer- Overrides:
startElementin classPrintConsumer
-
isHtmlEmptyElementTag
-
getHtmlTag
-
endElement
public void endElement()- Specified by:
endElementin interfaceConsumer- Overrides:
endElementin classPrintConsumer
-
startAttribute
Write a attribute for the current element. This is only allowed immediately after a startElement.- Specified by:
startAttributein interfaceConsumer- Overrides:
startAttributein classPrintConsumer
-
endAttribute
public void endAttribute()Description copied from interface:ConsumerEnd of an attribute or end of an actual parameter. The former use matches a startAttribute; the latter may not, and can be used to separate parameters in a parameter list. This double duty suggsts the method should at least be re-named.- Specified by:
endAttributein interfaceConsumer- Overrides:
endAttributein classPrintConsumer
-
writeDouble
public void writeDouble(double d) - Specified by:
writeDoublein interfaceConsumer- Overrides:
writeDoublein classPrintConsumer
-
writeFloat
public void writeFloat(float f) - Specified by:
writeFloatin interfaceConsumer- Overrides:
writeFloatin classPrintConsumer
-
formatDouble
Helper to format xs:double according to XPath/XQuery specification. -
formatFloat
Helper to format xs:float according to XPath/XQuery specification. -
formatDecimal
Format java.math.BigDecimal as needed for XPath/XQuery's xs:decimal. Specifically this means removing trailing fractional zeros, and a trailing decimal point. However, note that the XML Schema canonical representation does require a decimal point and at least one fractional digit. -
print
- Overrides:
printin classPrintWriter
-
writeObject
- Specified by:
writeObjectin interfaceConsumer- Overrides:
writeObjectin classPrintConsumer
-
ignoring
public boolean ignoring()True if consumer is ignoring rest of element. The producer can use this information to skip ahead.- Specified by:
ignoringin interfaceConsumer- Overrides:
ignoringin classPrintConsumer
-
write
- Overrides:
writein classPrintWriter
-
write
public void write(char[] buf, int off, int len) - Specified by:
writein interfaceConsumer- Overrides:
writein classPrintWriter
-
writePosition
Description copied from interface:PositionConsumerConsume a single position pair. This PositionConsumer may assume the sequence does no reference management; i.e. that copyPos is trivial and releasePos is a no-op. If that is not the case, use consume(TreePosition) instead.- Specified by:
writePositionin interfacePositionConsumer
-
writeBaseUri
-
beginComment
public void beginComment() -
endComment
public void endComment() -
writeComment
-
writeComment
public void writeComment(char[] chars, int offset, int length) - Specified by:
writeCommentin interfaceXConsumer- Overrides:
writeCommentin classPrintConsumer
-
writeCDATA
public void writeCDATA(char[] chars, int offset, int length) - Specified by:
writeCDATAin interfaceXConsumer- Overrides:
writeCDATAin classPrintConsumer
-
writeProcessingInstruction
- Specified by:
writeProcessingInstructionin interfaceXConsumer- Overrides:
writeProcessingInstructionin classPrintConsumer
-
writePosition
Description copied from interface:PositionConsumerConsume node at current position. The caller may invalidate or change the position after consume returns, so if the consumer wants to save it, it needs to copy it.- Specified by:
writePositionin interfacePositionConsumer
-
error
-