|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.android.utils.XmlUtils
public class XmlUtils
XML Utilities
Field Summary | |
---|---|
static java.lang.String |
XML_COMMENT_BEGIN
|
static java.lang.String |
XML_COMMENT_END
|
static java.lang.String |
XML_PROLOG
|
Constructor Summary | |
---|---|
XmlUtils()
|
Method Summary | |
---|---|
static void |
appendXmlAttributeValue(java.lang.StringBuilder sb,
java.lang.String attrValue)
Appends text to the given StringBuilder and escapes it as required for a
DOM attribute node. |
static void |
appendXmlTextValue(java.lang.StringBuilder sb,
java.lang.String textValue)
Appends text to the given StringBuilder and escapes it as required for a
DOM text node. |
static java.lang.String |
formatFloatAttribute(double value)
Format the given floating value into an XML string, omitting decimals if 0 |
static boolean |
hasElementChildren(org.w3c.dom.Node node)
Returns true if the given node has one or more element children |
static java.lang.String |
lookupNamespacePrefix(org.w3c.dom.Node node,
java.lang.String nsUri)
Returns the namespace prefix matching the requested namespace URI. |
static java.lang.String |
lookupNamespacePrefix(org.w3c.dom.Node node,
java.lang.String nsUri,
boolean create)
Returns the namespace prefix matching the requested namespace URI. |
static java.lang.String |
lookupNamespacePrefix(org.w3c.dom.Node node,
java.lang.String nsUri,
java.lang.String defaultPrefix,
boolean create)
Returns the namespace prefix matching the requested namespace URI. |
static org.w3c.dom.Document |
parseDocumentSilently(java.lang.String xml,
boolean namespaceAware)
Parses the given XML string as a DOM document, using the JDK parser. |
static java.lang.String |
toXml(org.w3c.dom.Node node,
boolean preserveWhitespace)
Dump an XML tree to string. |
static java.lang.String |
toXmlAttributeValue(java.lang.String attrValue)
Converts the given attribute value to an XML-attribute-safe value, meaning that single and double quotes are replaced with their corresponding XML entities. |
static java.lang.String |
toXmlTextValue(java.lang.String textValue)
Converts the given attribute value to an XML-text-safe value, meaning that less than and ampersand characters are escaped. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String XML_COMMENT_BEGIN
public static final java.lang.String XML_COMMENT_END
public static final java.lang.String XML_PROLOG
Constructor Detail |
---|
public XmlUtils()
Method Detail |
---|
@NonNull public static java.lang.String lookupNamespacePrefix(@NonNull org.w3c.dom.Node node, @NonNull java.lang.String nsUri)
lookupNamespacePrefix(Node, String, boolean)
instead.
node
- The current node. Must not be null.nsUri
- The namespace URI of which the prefix is to be found,
e.g. SdkConstants.ANDROID_URI
@NonNull public static java.lang.String lookupNamespacePrefix(@NonNull org.w3c.dom.Node node, @NonNull java.lang.String nsUri, boolean create)
node
- The current node. Must not be null.nsUri
- The namespace URI of which the prefix is to be found, e.g.
SdkConstants.ANDROID_URI
create
- whether the namespace declaration should be created, if
necessary
public static java.lang.String lookupNamespacePrefix(@Nullable org.w3c.dom.Node node, @Nullable java.lang.String nsUri, @Nullable java.lang.String defaultPrefix, boolean create)
node
- The current node. Must not be null.nsUri
- The namespace URI of which the prefix is to be found, e.g.
SdkConstants.ANDROID_URI
defaultPrefix
- The default prefix (root) to use if the namespace is
not found. If null, do not create a new namespace if this URI
is not defined for the document.create
- whether the namespace declaration should be created, if
necessary
@NonNull public static java.lang.String toXmlAttributeValue(@NonNull java.lang.String attrValue)
attrValue
- the value to be escaped
@NonNull public static java.lang.String toXmlTextValue(@NonNull java.lang.String textValue)
textValue
- the text value to be escaped
public static void appendXmlAttributeValue(@NonNull java.lang.StringBuilder sb, @NonNull java.lang.String attrValue)
StringBuilder
and escapes it as required for a
DOM attribute node.
sb
- the string builderattrValue
- the attribute value to be appended and escapedpublic static void appendXmlTextValue(@NonNull java.lang.StringBuilder sb, @NonNull java.lang.String textValue)
StringBuilder
and escapes it as required for a
DOM text node.
sb
- the string buildertextValue
- the text value to be appended and escapedpublic static boolean hasElementChildren(@NonNull org.w3c.dom.Node node)
node
- the node to test for element children
@Nullable public static org.w3c.dom.Document parseDocumentSilently(@NonNull java.lang.String xml, boolean namespaceAware)
xml
- the XML content to be parsed (must be well formed)namespaceAware
- whether the parser is namespace aware
public static java.lang.String toXml(org.w3c.dom.Node node, boolean preserveWhitespace)
XmlPrettyPrinter.prettyPrint(node)
in
sdk-common
.
public static java.lang.String formatFloatAttribute(double value)
value
- the value to be formatted
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |