public class XmlUtils
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static void |
xmlAppendAttr(java.lang.String attrName,
java.lang.String attrValue,
java.lang.Appendable buf)
Writes out an attribute for an element.
|
static void |
xmlAppendAttrValue(java.lang.String attrValue,
java.lang.Appendable buf)
XML encodes an attribute value, escaping some characters as
character entities, and dropping invalid control characters.
|
static void |
xmlAppendAttrValuePair(java.lang.String attrName,
java.lang.String attrValue,
java.lang.StringBuffer buf)
Deprecated.
|
static void |
xmlAppendEndTag(java.lang.String tag,
java.lang.Appendable buf)
Wraps an xm tag with '</' and '>'.
|
static void |
xmlAppendStartTag(java.lang.String tag,
java.lang.Appendable buf)
Wraps an xm tag with '<' and '>'.
|
static void |
XmlEncodeAttrValue(java.lang.String attrValue,
java.lang.StringBuffer buf)
Deprecated.
|
static java.lang.String |
xmlWrapEnd(java.lang.String str)
Wraps an xml tag with '</' and '>'.
|
static java.lang.String |
xmlWrapStart(java.lang.String str)
Wraps an xm tag with '<' and '>'.
|
public static java.lang.String xmlWrapStart(java.lang.String str)
public static java.lang.String xmlWrapEnd(java.lang.String str)
@Deprecated public static void XmlEncodeAttrValue(java.lang.String attrValue, java.lang.StringBuffer buf)
xmlAppendAttrValue(String, Appendable)
.attrValue
- the attribute valuebuf
- the StringBuffer
to which to append the attribute@Deprecated public static void xmlAppendAttrValuePair(java.lang.String attrName, java.lang.String attrValue, java.lang.StringBuffer buf)
xmlAppendAttr(String, String, Appendable)
.For example, given attrName="foo" and attrValue="val<bar" writes out:
foo="val<bar"
attrName
- the attribute nameattrValue
- the attribute valuebuf
- the StringBuffer
to which to append the attributepublic static void xmlAppendStartTag(java.lang.String tag, java.lang.Appendable buf) throws java.io.IOException
tag
- the XML tag to wrap with '<' and '>'buf
- the Appendable
to which to append the start tagjava.io.IOException
- from Appendable
(but StringBuffer
or
StringBuilder
will never actually throw IOException
)public static void xmlAppendEndTag(java.lang.String tag, java.lang.Appendable buf) throws java.io.IOException
tag
- the XML tag to wrap with '</' and '>'buf
- the Appendable
to which to append the start tagjava.io.IOException
- from Appendable
(but StringBuffer
or
StringBuilder
will never actually throw IOException
)public static void xmlAppendAttr(java.lang.String attrName, java.lang.String attrValue, java.lang.Appendable buf) throws java.io.IOException
null
and non-empty, then the attribute is written out,
preceded by a single space.
The given value will be XML encoded before appending to the buffer.
For example, given attrName="foo" and attrValue="val<bar" writes out:
foo="val<bar"
attrName
- the attribute nameattrValue
- the attribute valuebuf
- the Appendable
to which to append the attribute
name-value pairjava.io.IOException
- from Appendable
(but StringBuffer
or
StringBuilder
will never actually throw IOException
)public static void xmlAppendAttrValue(java.lang.String attrValue, java.lang.Appendable buf) throws java.io.IOException
Only four characters need to be encoded, according to the
W3C XML 1.0 Specification Character definition: < & " '
(less-than, ampersand, double-quote, single-quote).
Actually, we could only encode one of the quote characters if we knew that that was the one used to wrap the value, but we'll play it safe and encode both.
We drop invalid XML characters, following the W3C XML 1.0 Specification Character definition:
Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]Java uses UTF-16 internally, so Unicode characters U+10000 to U+10FFFF are encoded using the surrogate characters excluded above, 0xD800 to 0xDFFF. So we allow just 0x09, 0x0A, 0x0D, and the range 0x20 to 0xFFFD.
attrValue
- the attribute valuebuf
- the Appendable
to which to append the attribute valuejava.io.IOException
- from Appendable
(but StringBuffer
or
StringBuilder
will never actually throw IOException
)