Пример #1
0
		/// <exception cref="org.xmlpull.v1.XmlPullParserException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private static object readThisValueXml(org.xmlpull.v1.XmlPullParser parser, string
			[] name)
		{
			string valueName = parser.getAttributeValue(null, "name");
			string tagName = parser.getName();
			//System.out.println("Reading this value tag: " + tagName + ", name=" + valueName);
			object res;
			if (tagName.Equals("null"))
			{
				res = null;
			}
			else
			{
				if (tagName.Equals("string"))
				{
					string value = string.Empty;
					int eventType;
					while ((eventType = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT
						)
					{
						if (eventType == org.xmlpull.v1.XmlPullParserClass.END_TAG)
						{
							if (parser.getName().Equals("string"))
							{
								name[0] = valueName;
								//System.out.println("Returning value for " + valueName + ": " + value);
								return value;
							}
							throw new org.xmlpull.v1.XmlPullParserException("Unexpected end tag in <string>: "
								 + parser.getName());
						}
						else
						{
							if (eventType == org.xmlpull.v1.XmlPullParserClass.TEXT)
							{
								value += parser.getText();
							}
							else
							{
								if (eventType == org.xmlpull.v1.XmlPullParserClass.START_TAG)
								{
									throw new org.xmlpull.v1.XmlPullParserException("Unexpected start tag in <string>: "
										 + parser.getName());
								}
							}
						}
					}
					throw new org.xmlpull.v1.XmlPullParserException("Unexpected end of document in <string>"
						);
				}
				else
				{
					if (tagName.Equals("int"))
					{
						res = System.Convert.ToInt32(parser.getAttributeValue(null, "value"));
					}
					else
					{
						if (tagName.Equals("long"))
						{
							res = long.Parse(parser.getAttributeValue(null, "value"));
						}
						else
						{
							if (tagName.Equals("float"))
							{
								res = System.Convert.ToSingle(parser.getAttributeValue(null, "value"));
							}
							else
							{
								if (tagName.Equals("double"))
								{
									res = System.Convert.ToDouble(parser.getAttributeValue(null, "value"));
								}
								else
								{
									if (tagName.Equals("boolean"))
									{
										res = bool.Parse(parser.getAttributeValue(null, "value"));
									}
									else
									{
										if (tagName.Equals("int-array"))
										{
											parser.next();
											res = readThisIntArrayXml(parser, "int-array", name);
											name[0] = valueName;
											//System.out.println("Returning value for " + valueName + ": " + res);
											return res;
										}
										else
										{
											if (tagName.Equals("map"))
											{
												parser.next();
												res = readThisMapXml(parser, "map", name);
												name[0] = valueName;
												//System.out.println("Returning value for " + valueName + ": " + res);
												return res;
											}
											else
											{
												if (tagName.Equals("list"))
												{
													parser.next();
													res = readThisListXml(parser, "list", name);
													name[0] = valueName;
													//System.out.println("Returning value for " + valueName + ": " + res);
													return res;
												}
												else
												{
													if (tagName.Equals("set"))
													{
														parser.next();
														res = readThisSetXml(parser, "set", name);
														name[0] = valueName;
														//System.out.println("Returning value for " + valueName + ": " + res);
														return res;
													}
													else
													{
														throw new org.xmlpull.v1.XmlPullParserException("Unknown tag: " + tagName);
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
			// Skip through to end tag.
			int eventType_1;
			while ((eventType_1 = parser.next()) != org.xmlpull.v1.XmlPullParserClass.END_DOCUMENT
				)
			{
				if (eventType_1 == org.xmlpull.v1.XmlPullParserClass.END_TAG)
				{
					if (parser.getName().Equals(tagName))
					{
						name[0] = valueName;
						//System.out.println("Returning value for " + valueName + ": " + res);
						return res;
					}
					throw new org.xmlpull.v1.XmlPullParserException("Unexpected end tag in <" + tagName
						 + ">: " + parser.getName());
				}
				else
				{
					if (eventType_1 == org.xmlpull.v1.XmlPullParserClass.TEXT)
					{
						throw new org.xmlpull.v1.XmlPullParserException("Unexpected text in <" + tagName 
							+ ">: " + parser.getName());
					}
					else
					{
						if (eventType_1 == org.xmlpull.v1.XmlPullParserClass.START_TAG)
						{
							throw new org.xmlpull.v1.XmlPullParserException("Unexpected start tag in <" + tagName
								 + ">: " + parser.getName());
						}
					}
				}
			}
			throw new org.xmlpull.v1.XmlPullParserException("Unexpected end of document in <"
				 + tagName + ">");
		}
Пример #2
0
		/// <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");
		}