/// <summary>Read a flattened object from an XmlPullParser.</summary> /// <remarks> /// Read a flattened object from an XmlPullParser. The XML data could /// previously have been written with writeMapXml(), writeListXml(), or /// writeValueXml(). The XmlPullParser must be positioned <em>at</em> the /// tag that defines the value. /// </remarks> /// <param name="parser">The XmlPullParser from which to read the object.</param> /// <param name="name"> /// An array of one string, used to return the name attribute /// of the value's tag. /// </param> /// <returns>Object The newly generated value object.</returns> /// <seealso cref="readMapXml(java.io.InputStream)">readMapXml(java.io.InputStream)</seealso> /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream) /// </seealso> /// <seealso cref="writeValueXml(object, string, org.xmlpull.v1.XmlSerializer)">writeValueXml(object, string, org.xmlpull.v1.XmlSerializer) /// </seealso> /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception> /// <exception cref="System.IO.IOException"></exception> public static object readValueXml(org.xmlpull.v1.XmlPullParser parser, string[] name ) { int eventType = parser.getEventType(); do { if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG) { return readThisValueXml(parser, name); } else { if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG) { throw new org.xmlpull.v1.XmlPullParserException("Unexpected end tag at: " + parser .getName()); } else { if (eventType == org.xmlpull.v1.XmlPullParserClass.TEXT) { throw new org.xmlpull.v1.XmlPullParserException("Unexpected text: " + parser.getText ()); } } } eventType = parser.next(); } while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT); throw new org.xmlpull.v1.XmlPullParserException("Unexpected end of document"); }
/// <summary>Read a HashSet object from an XmlPullParser.</summary> /// <remarks> /// Read a HashSet object from an XmlPullParser. The XML data could previously /// have been generated by writeSetXml(). The XmlPullParser must be positioned /// <em>after</em> the tag that begins the set. /// </remarks> /// <param name="parser">The XmlPullParser from which to read the set data.</param> /// <param name="endTag">Name of the tag that will end the set, usually "set".</param> /// <param name="name"> /// An array of one string, used to return the name attribute /// of the set's tag. /// </param> /// <returns>HashSet The newly generated set.</returns> /// <exception cref="org.xmlpull.v1.XmlPullParserException">org.xmlpull.v1.XmlPullParserException /// </exception> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> /// <seealso cref="readSetXml(java.io.InputStream)">readSetXml(java.io.InputStream)</seealso> public static java.util.HashSet<object> readThisSetXml(org.xmlpull.v1.XmlPullParser parser, string endTag, string[] name) { java.util.HashSet<object> set = new java.util.HashSet<object>(); int eventType = parser.getEventType(); do { if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG) { object val = readThisValueXml(parser, name); set.add(val); } else { //System.out.println("Adding to set: " + val); if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG) { if (parser.getName().Equals(endTag)) { return set; } throw new org.xmlpull.v1.XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName()); } } eventType = parser.next(); } while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT); throw new org.xmlpull.v1.XmlPullParserException("Document ended before " + endTag + " end tag"); }
/// <summary>Read an int[] object from an XmlPullParser.</summary> /// <remarks> /// Read an int[] object from an XmlPullParser. The XML data could /// previously have been generated by writeIntArrayXml(). The XmlPullParser /// must be positioned <em>after</em> the tag that begins the list. /// </remarks> /// <param name="parser">The XmlPullParser from which to read the list data.</param> /// <param name="endTag">Name of the tag that will end the list, usually "list".</param> /// <param name="name"> /// An array of one string, used to return the name attribute /// of the list's tag. /// </param> /// <returns>Returns a newly generated int[].</returns> /// <seealso cref="readListXml(java.io.InputStream)">readListXml(java.io.InputStream) /// </seealso> /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception> /// <exception cref="System.IO.IOException"></exception> public static int[] readThisIntArrayXml(org.xmlpull.v1.XmlPullParser parser, string endTag, string[] name) { int num; try { num = System.Convert.ToInt32(parser.getAttributeValue(null, "num")); } catch (System.ArgumentNullException) { throw new org.xmlpull.v1.XmlPullParserException("Need num attribute in byte-array" ); } catch (System.ArgumentException) { throw new org.xmlpull.v1.XmlPullParserException("Not a number in num attribute in byte-array" ); } int[] array = new int[num]; int i = 0; int eventType = parser.getEventType(); do { if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG) { if (parser.getName().Equals("item")) { try { array[i] = System.Convert.ToInt32(parser.getAttributeValue(null, "value")); } catch (System.ArgumentNullException) { throw new org.xmlpull.v1.XmlPullParserException("Need value attribute in item"); } catch (System.ArgumentException) { throw new org.xmlpull.v1.XmlPullParserException("Not a number in value attribute in item" ); } } else { throw new org.xmlpull.v1.XmlPullParserException("Expected item tag at: " + parser .getName()); } } else { if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG) { if (parser.getName().Equals(endTag)) { return array; } else { if (parser.getName().Equals("item")) { i++; } else { throw new org.xmlpull.v1.XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName()); } } } } eventType = parser.next(); } while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT); throw new org.xmlpull.v1.XmlPullParserException("Document ended before " + endTag + " end tag"); }
/// <summary>Read a HashMap object from an XmlPullParser.</summary> /// <remarks> /// Read a HashMap object from an XmlPullParser. The XML data could /// previously have been generated by writeMapXml(). The XmlPullParser /// must be positioned <em>after</em> the tag that begins the map. /// </remarks> /// <param name="parser">The XmlPullParser from which to read the map data.</param> /// <param name="endTag">Name of the tag that will end the map, usually "map".</param> /// <param name="name"> /// An array of one string, used to return the name attribute /// of the map's tag. /// </param> /// <returns>HashMap The newly generated map.</returns> /// <seealso cref="readMapXml(java.io.InputStream)">readMapXml(java.io.InputStream)</seealso> /// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception> /// <exception cref="System.IO.IOException"></exception> public static java.util.HashMap<object, object> readThisMapXml(org.xmlpull.v1.XmlPullParser parser, string endTag, string[] name) { java.util.HashMap<object, object> map = new java.util.HashMap<object, object>(); int eventType = parser.getEventType(); do { if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG) { object val = readThisValueXml(parser, name); if (name[0] != null) { //System.out.println("Adding to map: " + name + " -> " + val); map.put(name[0], val); } else { throw new org.xmlpull.v1.XmlPullParserException("Map value without name attribute: " + parser.getName()); } } else { if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG) { if (parser.getName().Equals(endTag)) { return map; } throw new org.xmlpull.v1.XmlPullParserException("Expected " + endTag + " end tag at: " + parser.getName()); } } eventType = parser.next(); } while (eventType != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT); throw new org.xmlpull.v1.XmlPullParserException("Document ended before " + endTag + " end tag"); }