Package com.google.api.client.xml
Class Xml
java.lang.Object
com.google.api.client.xml.Xml
Beta
XML utilities.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Customizes the behavior of XML parsing. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.xmlpull.v1.XmlPullParser
Returns a new XML pull parser.static org.xmlpull.v1.XmlSerializer
Returns a new XML serializer.private static String
getFieldName
(boolean isAttribute, String alias, String namespace, String name) private static org.xmlpull.v1.XmlPullParserFactory
private static void
parseAttributeOrTextContent
(String stringValue, Field field, Type valueType, List<Type> context, Object destination, GenericXml genericXml, Map<String, Object> destinationMap, String name) Parses the string value of an attribute value or text content.static void
parseElement
(org.xmlpull.v1.XmlPullParser parser, Object destination, XmlNamespaceDictionary namespaceDictionary, Xml.CustomizeParser customizeParser) Parses an XML element using the given XML pull parser into the given destination object.private static boolean
parseElementInternal
(org.xmlpull.v1.XmlPullParser parser, ArrayList<Type> context, Object destination, Type valueType, XmlNamespaceDictionary namespaceDictionary, Xml.CustomizeParser customizeParser) Returns whether the customize parser has requested to stop or reached end of document.private static void
parseNamespacesForElement
(org.xmlpull.v1.XmlPullParser parser, XmlNamespaceDictionary namespaceDictionary) Parses the namespaces declared on the current element into the namespace dictionary.private static Object
parseTextContentForElement
(org.xmlpull.v1.XmlPullParser parser, List<Type> context, boolean ignoreTextContent, Type textContentType) private static Object
parseValue
(Type valueType, List<Type> context, String value) private static void
setValue
(Object value, Field field, Object destination, GenericXml genericXml, Map<String, Object> destinationMap, String name) Sets the value of a given field or map entry.static String
toStringOf
(Object element) Shows a debug string representation of an element data object of key/value pairs.
-
Field Details
-
MEDIA_TYPE
"application/xml; charset=utf-8"
media type used as a default for XML parsing.Use
HttpMediaType.equalsIgnoreParameters(com.google.api.client.http.HttpMediaType)
for comparing media types.- Since:
- 1.10
-
TEXT_CONTENT
Text content.- See Also:
-
factory
private static org.xmlpull.v1.XmlPullParserFactory factoryXML pull parser factory.
-
-
Constructor Details
-
Xml
private Xml()
-
-
Method Details
-
getParserFactory
private static org.xmlpull.v1.XmlPullParserFactory getParserFactory() throws org.xmlpull.v1.XmlPullParserException- Throws:
org.xmlpull.v1.XmlPullParserException
-
createSerializer
public static org.xmlpull.v1.XmlSerializer createSerializer()Returns a new XML serializer.- Throws:
IllegalArgumentException
- if encountered anXmlPullParserException
-
createParser
public static org.xmlpull.v1.XmlPullParser createParser() throws org.xmlpull.v1.XmlPullParserExceptionReturns a new XML pull parser.- Throws:
org.xmlpull.v1.XmlPullParserException
-
toStringOf
Shows a debug string representation of an element data object of key/value pairs.It will make up something for the element name and XML namespaces. If those are known, it is better to use
XmlNamespaceDictionary.toStringOf(String, Object)
.- Parameters:
element
- element data object of key/value pairs (GenericXml
,Map
, or any object with public fields)
-
parseAttributeOrTextContent
private static void parseAttributeOrTextContent(String stringValue, Field field, Type valueType, List<Type> context, Object destination, GenericXml genericXml, Map<String, Object> destinationMap, String name) Parses the string value of an attribute value or text content.- Parameters:
stringValue
- string valuefield
- field to set ornull
if not applicablevalueType
- value type (class, parameterized type, or generic array type) ornull
for nonecontext
- context list, going from least specific to most specific type context, for example container class and its fielddestination
- destination object ornull
for nonegenericXml
- generic XML ornull
if not applicabledestinationMap
- destination map ornull
if not applicablename
- key name
-
setValue
private static void setValue(Object value, Field field, Object destination, GenericXml genericXml, Map<String, Object> destinationMap, String name) Sets the value of a given field or map entry.- Parameters:
value
- valuefield
- field to set ornull
if not applicabledestination
- destination object ornull
for nonegenericXml
- generic XML ornull
if not applicabledestinationMap
- destination map ornull
if not applicablename
- key name
-
parseElement
public static void parseElement(org.xmlpull.v1.XmlPullParser parser, Object destination, XmlNamespaceDictionary namespaceDictionary, Xml.CustomizeParser customizeParser) throws IOException, org.xmlpull.v1.XmlPullParserException Parses an XML element using the given XML pull parser into the given destination object.Requires the current event be
XmlPullParser.START_TAG
(skipping any initialXmlPullParser.START_DOCUMENT
) of the element being parsed. At normal parsing completion, the current event will either beXmlPullParser.END_TAG
of the element being parsed, or theXmlPullParser.START_TAG
of the requestedatom:entry
.- Parameters:
parser
- XML pull parserdestination
- optional destination object to parser into ornull
to ignore XML contentnamespaceDictionary
- XML namespace dictionary to store unknown namespacescustomizeParser
- optional parser customizer ornull
for none- Throws:
IOException
org.xmlpull.v1.XmlPullParserException
-
parseElementInternal
private static boolean parseElementInternal(org.xmlpull.v1.XmlPullParser parser, ArrayList<Type> context, Object destination, Type valueType, XmlNamespaceDictionary namespaceDictionary, Xml.CustomizeParser customizeParser) throws IOException, org.xmlpull.v1.XmlPullParserException Returns whether the customize parser has requested to stop or reached end of document. Otherwise, identical toparseElement(XmlPullParser, Object, XmlNamespaceDictionary, CustomizeParser)
.- Throws:
IOException
org.xmlpull.v1.XmlPullParserException
-
getFieldName
-
parseTextContentForElement
private static Object parseTextContentForElement(org.xmlpull.v1.XmlPullParser parser, List<Type> context, boolean ignoreTextContent, Type textContentType) throws org.xmlpull.v1.XmlPullParserException, IOException - Throws:
org.xmlpull.v1.XmlPullParserException
IOException
-
parseValue
-
parseNamespacesForElement
private static void parseNamespacesForElement(org.xmlpull.v1.XmlPullParser parser, XmlNamespaceDictionary namespaceDictionary) throws org.xmlpull.v1.XmlPullParserException Parses the namespaces declared on the current element into the namespace dictionary.- Parameters:
parser
- XML pull parsernamespaceDictionary
- namespace dictionary- Throws:
org.xmlpull.v1.XmlPullParserException
-