Class Xml
java.lang.Object
com.google.api.client.xml.Xml
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classCustomizes the behavior of XML parsing. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.xmlpull.v1.XmlPullParserReturns a new XML pull parser.static org.xmlpull.v1.XmlSerializerReturns a new XML serializer.private static StringgetFieldName(boolean isAttribute, String alias, String namespace, String name) private static org.xmlpull.v1.XmlPullParserFactoryprivate static voidparseAttributeOrTextContent(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 voidparseElement(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 booleanparseElementInternal(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 voidparseNamespacesForElement(org.xmlpull.v1.XmlPullParser parser, XmlNamespaceDictionary namespaceDictionary) Parses the namespaces declared on the current element into the namespace dictionary.private static ObjectparseTextContentForElement(org.xmlpull.v1.XmlPullParser parser, List<Type> context, boolean ignoreTextContent, Type textContentType) private static ObjectparseValue(Type valueType, List<Type> context, String value) private static voidsetValue(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 StringtoStringOf(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(HttpMediaType)for comparing media types.- Since:
- 1.10
-
TEXT_CONTENT
-
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 ornullif not applicablevalueType- value type (class, parameterized type, or generic array type) ornullfor nonecontext- context list, going from least specific to most specific type context, for example container class and its fielddestination- destination object ornullfor nonegenericXml- generic XML ornullif not applicabledestinationMap- destination map ornullif 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 ornullif not applicabledestination- destination object ornullfor nonegenericXml- generic XML ornullif not applicabledestinationMap- destination map ornullif 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_TAGof the element being parsed, or theXmlPullParser.START_TAGof the requestedatom:entry.- Parameters:
parser- XML pull parserdestination- optional destination object to parser into ornullto ignore XML contentnamespaceDictionary- XML namespace dictionary to store unknown namespacescustomizeParser- optional parser customizer ornullfor none- Throws:
IOExceptionorg.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:
IOExceptionorg.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.XmlPullParserExceptionIOException
-
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
-