@Beta public final class XmlNamespaceDictionary extends java.lang.Object
Beta Implementation is thread-safe. For maximum efficiency, applications should use a single globally-shared instance of the XML namespace dictionary.
A namespace alias is uniquely mapped to a single namespace URI, and a namespace URI is uniquely mapped to a single namespace alias. In other words, it is not possible to have duplicates.
Sample usage:
static final XmlNamespaceDictionary DICTIONARY = new XmlNamespaceDictionary()
.set("", "http://www.w3.org/2005/Atom")
.set("activity", "http://activitystrea.ms/spec/1.0/")
.set("georss", "http://www.georss.org/georss")
.set("media", "http://search.yahoo.com/mrss/")
.set("thr", "http://purl.org/syndication/thread/1.0");
| Constructor and Description |
|---|
XmlNamespaceDictionary() |
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getAliasForUri(java.lang.String uri)
Returns the namespace alias (or
"" for the default namespace) for the given namespace
URI. |
java.util.Map<java.lang.String,java.lang.String> |
getAliasToUriMap()
Returns an unmodified set of map entries for the map from namespace alias (or
"" for
the default namespace) to namespace URI. |
java.lang.String |
getUriForAlias(java.lang.String alias)
Returns the namespace URI for the given namespace alias (or
"" for the default
namespace). |
java.util.Map<java.lang.String,java.lang.String> |
getUriToAliasMap()
Returns an unmodified set of map entries for the map from namespace URI to namespace alias (or
"" for the default namespace). |
void |
serialize(org.xmlpull.v1.XmlSerializer serializer,
java.lang.String elementName,
java.lang.Object element)
Shows a debug string representation of an element data object of key/value pairs.
|
void |
serialize(org.xmlpull.v1.XmlSerializer serializer,
java.lang.String elementNamespaceUri,
java.lang.String elementLocalName,
java.lang.Object element)
Shows a debug string representation of an element data object of key/value pairs.
|
XmlNamespaceDictionary |
set(java.lang.String alias,
java.lang.String uri)
Adds a namespace of the given alias and URI.
|
java.lang.String |
toStringOf(java.lang.String elementName,
java.lang.Object element)
Shows a debug string representation of an element data object of key/value pairs.
|
public java.lang.String getAliasForUri(java.lang.String uri)
"" for the default namespace) for the given namespace
URI.uri - namespace URIpublic java.lang.String getUriForAlias(java.lang.String alias)
"" for the default
namespace).alias - namespace alias (or "" for the default namespace)public java.util.Map<java.lang.String,java.lang.String> getAliasToUriMap()
"" for
the default namespace) to namespace URI.public java.util.Map<java.lang.String,java.lang.String> getUriToAliasMap()
"" for the default namespace).public XmlNamespaceDictionary set(java.lang.String alias, java.lang.String uri)
If the uri is null, the namespace alias will be removed. Similarly, if the alias is
null, the namespace URI will be removed. Otherwise, if the alias is already mapped to a
different URI, it will be remapped to the new URI. Similarly, if a URI is already mapped to a
different alias, it will be remapped to the new alias.
alias - alias or null to remove the namespace URIuri - namespace URI or null to remove the namespace aliaspublic java.lang.String toStringOf(java.lang.String elementName,
java.lang.Object element)
element - element data object (GenericXml, Map, or any object with public
fields)elementName - optional XML element local name prefixed by its namespace alias -- for
example "atom:entry" -- or null to make up somethingpublic void serialize(org.xmlpull.v1.XmlSerializer serializer,
java.lang.String elementNamespaceUri,
java.lang.String elementLocalName,
java.lang.Object element)
throws java.io.IOException
element - element data object (GenericXml, Map, or any object with public
fields)elementNamespaceUri - XML namespace URI or null for no namespaceelementLocalName - XML local namejava.io.IOException - I/O exceptionpublic void serialize(org.xmlpull.v1.XmlSerializer serializer,
java.lang.String elementName,
java.lang.Object element)
throws java.io.IOException
element - element data object (GenericXml, Map, or any object with public
fields)elementName - XML element local name prefixed by its namespace aliasjava.io.IOException - I/O exceptionCopyright © 2011-2018 Google. All Rights Reserved.