public override void parseBody(XmlPullParser parser) { bodyIn = null; parser.nextTag(); if (parser.getEventType() == XmlPullParser.START_TAG && parser.getNamespace().Equals(env) && parser.getName().Equals("Fault")) { SoapFault fault; if (this.version < SoapEnvelope.VER12) { fault = new SoapFault(this.version); } else { fault = new SoapFault12(this.version); } fault.parse(parser); bodyIn = fault; } else { while (parser.getEventType() == XmlPullParser.START_TAG) { String rootAttr = parser.getAttributeValue(enc, ROOT_LABEL); Object o = read(parser, null, -1, parser.getNamespace(), parser.getName(), PropertyInfo.OBJECT_TYPE); if ("1".Equals(rootAttr) || bodyIn == null) { bodyIn = o; } parser.nextTag(); } } }
/** Recursively builds the child elements from the given parser * until an end tag or end document is found. * The end tag is not consumed. */ public virtual void parse(XmlPullParser parser) { bool leave = false; do { int type = parser.getEventType(); // System.out.println(parser.getPositionDescription()); switch (type) { case XmlPullParser.START_TAG: { Element child = createElement( parser.getNamespace(), parser.getName()); // child.setAttributes (event.getAttributes ()); addChild(ELEMENT, child); // order is important here since // setparent may perform some init code! child.parse(parser); break; } case XmlPullParser.END_DOCUMENT: case XmlPullParser.END_TAG: leave = true; break; default: if (parser.getText() != null) { addChild( type == XmlPullParser.ENTITY_REF ? TEXT : type, parser.getText()); } else if ( type == XmlPullParser.ENTITY_REF && parser.getName() != null) { addChild(ENTITY_REF, parser.getName()); } parser.nextToken(); break; } } while (!leave); }
public virtual void parseBody(XmlPullParser parser) { parser.nextTag(); // insert fault generation code here if (parser.getEventType() == XmlPullParser.START_TAG && parser.getNamespace().Equals(env) && parser.getName().Equals("Fault")) { SoapFault fault; if (this.version < SoapEnvelope.VER12) { fault = new SoapFault(this.version); } else { fault = new SoapFault12(this.version); } fault.parse(parser); bodyIn = fault; } else { Node node = (bodyIn is Node) ? (Node)bodyIn : new Node(); node.parse(parser); bodyIn = node; } }
public Object readInstance(XmlPullParser parser, String namespace_, String name, PropertyInfo expected) { Dictionary <object, object> instance = new Dictionary <object, object>(); String elementName = parser.getName(); while (parser.nextTag() != XmlPullParser.END_TAG) { SoapObject item = new ItemSoapObject(instance); parser.require(XmlPullParser.START_TAG, null, "item"); parser.nextTag(); Object key = envelope.read(parser, item, 0, null, null, PropertyInfo.OBJECT_TYPE); parser.nextTag(); if (key != null) { item.setProperty(0, key); } Object value = envelope.read(parser, item, 1, null, null, PropertyInfo.OBJECT_TYPE); parser.nextTag(); if (value != null) { item.setProperty(1, value); } parser.require(XmlPullParser.END_TAG, null, "item"); } parser.require(XmlPullParser.END_TAG, null, elementName); return(instance); }
void rInflate(XmlPullParser parser, View parent, AttributeSet attrs, bool finishInflate, bool inheritContext) { int depth = parser.getDepth(); int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if (type != XmlPullParser.START_TAG) { continue; } string name = parser.getName(); if (TAG_REQUEST_FOCUS.Equals(name)) { parseRequestFocus(parser, parent); } else if (TAG_TAG.Equals(name)) { parseViewTag(parser, parent, attrs); } if (TAG_INCLUDE.Equals(name)) { if (parser.getDepth() == 0) { throw new Exception("<include /> cannot be the root element"); } parseInclude(parser, parent, attrs, inheritContext); } else if (TAG_MERGE.Equals(name)) { throw new Exception("<merge /> must be the root element"); } else { View view = createViewFromTag(parent, name, attrs, inheritContext); ViewGroup viewGroup = (ViewGroup)parent; ViewGroup.LayoutParams lparams = viewGroup.generateLayoutParams(attrs); rInflate(parser, view, attrs, true, true); viewGroup.addView(view, lparams); } } if (finishInflate) { parent.onFinishInflate(); } }
/** Fills the fault details from the given XML stream */ public virtual void parse(XmlPullParser parser) { parser.require(XmlPullParser.START_TAG, SoapEnvelope.ENV, "Fault"); while (parser.nextTag() == XmlPullParser.START_TAG) { string name = parser.getName(); if (name.Equals("detail")) { detail = new Node(); detail.parse(parser); // Handle case '...<detail/></soap:Fault>' if (parser.getNamespace().Equals(SoapEnvelope.ENV) && parser.getName().Equals("Fault")) { break; } continue; } if (name.Equals("faultcode")) { faultcode = parser.nextText(); } else if (name.Equals("faultstring")) { faultstring = parser.nextText(); } else if (name.Equals("faultactor")) { faultactor = parser.nextText(); } else { throw new Exception("unexpected tag:" + name); } parser.require(XmlPullParser.END_TAG, null, name); } parser.require(XmlPullParser.END_TAG, SoapEnvelope.ENV, "Fault"); parser.nextTag(); }
/** * Create from inside an XML document. Called on a parser positioned at a * tag in an XML document, tries to create a ColorStateList from that tag. * * @throws XmlPullParserException if the current tag is not <selector> * @return A color state list for the current tag. */ private static ColorStateList createFromXmlInner(Resources r, XmlPullParser parser, AttributeSet attrs) { ColorStateList colorStateList; string name = parser.getName(); if (name.Equals("selector")) { colorStateList = new ColorStateList(); } else { throw new Exception(parser.getPositionDescription() + ": invalid drawable tag " + name); } //colorStateList.inflate(r, parser, attrs); return(colorStateList); }
private void parseSelf(XmlPullParser parser) { parser.require(XmlPullParser.START_TAG, SoapEnvelope.ENV2003, "Fault"); while (parser.nextTag() == XmlPullParser.START_TAG) { string name = parser.getName(); string namespace_ = parser.getNamespace(); parser.nextTag(); if (name.ToLower().Equals("Code".ToLower())) { Code = new Node(); Code.parse(parser); } else if (name.ToLower().Equals("Reason".ToLower())) { Reason = new Node(); Reason.parse(parser); } else if (name.ToLower().Equals("Node".ToLower())) { Node = new Node(); Node.parse(parser); } else if (name.ToLower().Equals("Role".ToLower())) { Role = new Node(); Role.parse(parser); } else if (name.ToLower().Equals("Detail".ToLower())) { Detail = new Node(); Detail.parse(parser); } else { throw new Exception("unexpected tag:" + name); } parser.require(XmlPullParser.END_TAG, namespace_, name); } parser.require(XmlPullParser.END_TAG, SoapEnvelope.ENV2003, "Fault"); parser.nextTag(); }
/** Parses the SOAP envelope from the given parser */ public void parse(XmlPullParser parser) { parser.nextTag(); parser.require(XmlPullParser.START_TAG, env, "Envelope"); encodingStyle = parser.getAttributeValue(env, "encodingStyle"); parser.nextTag(); if (parser.getEventType() == XmlPullParser.START_TAG && parser.getNamespace().Equals(env) && parser.getName().Equals("Header")) { parseHeader(parser); parser.require(XmlPullParser.END_TAG, env, "Header"); parser.nextTag(); } parser.require(XmlPullParser.START_TAG, env, "Body"); encodingStyle = parser.getAttributeValue(env, "encodingStyle"); parseBody(parser); parser.require(XmlPullParser.END_TAG, env, "Body"); parser.nextTag(); parser.require(XmlPullParser.END_TAG, env, "Envelope"); }
/** * Builds an object from the XML stream. This method is public for usage in conjuction with Marshal * subclasses. Precondition: On the start tag of the object or property, so href can be read. */ public Object read(XmlPullParser parser, Object owner, int index, String namespace_, String name, PropertyInfo expected) { String elementName = parser.getName(); String href = parser.getAttributeValue(null, HREF_LABEL); Object obj; if (href != null) { if (owner == null) { throw new Exception("href at root level?!?"); } href = getIdFromHref(href); obj = idMap[href]; if (obj == null || obj is FwdRef) { FwdRef f = new FwdRef(); f.next = (FwdRef)obj; f.obj = owner; f.index = index; idMap[href] = f; obj = null; } parser.nextTag(); // start tag parser.require(XmlPullParser.END_TAG, null, elementName); } else { String nullAttr = parser.getAttributeValue(xsi, NIL_LABEL); String id = parser.getAttributeValue(null, ID_LABEL); if (nullAttr == null) { nullAttr = parser.getAttributeValue(xsi, NULL_LABEL); } if (nullAttr != null && SoapEnvelope.stringToBoolean(nullAttr)) { obj = null; parser.nextTag(); parser.require(XmlPullParser.END_TAG, null, elementName); } else { String type = parser.getAttributeValue(xsi, TYPE_LABEL); if (type != null) { int cut = type.IndexOf(':'); name = type.Substring(cut + 1); String prefix = cut == -1 ? "" : type.Substring(0, cut); namespace_ = parser.getNamespace(prefix); } else if (name == null && namespace_ == null) { if (parser.getAttributeValue(enc, ARRAY_TYPE_LABEL) != null) { namespace_ = enc; name = ARRAY_MAPPING_NAME; } else { Object[] names = getInfo(expected.type, null); namespace_ = (String)names[0]; name = (String)names[1]; } } // be sure to set this flag if we don't know the types. if (type == null) { implicitTypes = true; } obj = readInstance(parser, namespace_, name, expected); if (obj == null) { obj = readUnknown(parser, namespace_, name); } } // finally, care about the id.... if (id != null) { resolveReference(id, obj); } } parser.require(XmlPullParser.END_TAG, null, elementName); return(obj); }
/** * If the type of the object cannot be determined, and thus no Marshal class can handle the object, this * method is called. It will build either a SoapPrimitive or a SoapObject * * @param parser * @param typeNamespace * @param typeName * @return unknownObject wrapped as a SoapPrimitive or SoapObject * @throws IOException * @throws XmlPullParserException */ protected Object readUnknown(XmlPullParser parser, String typeNamespace, String typeName) { String name = parser.getName(); String namespace_ = parser.getNamespace(); // cache the attribute info list from the current element before we move on List <object> attributeInfoVector = new List <object>(); for (int attributeCount = 0; attributeCount < parser.getAttributeCount(); attributeCount++) { AttributeInfo attributeInfo = new AttributeInfo(); attributeInfo.setName(parser.getAttributeName(attributeCount)); attributeInfo.setValue(parser.getAttributeValue(attributeCount)); attributeInfo.setNamespace(parser.getAttributeNamespace(attributeCount)); attributeInfo.setType(parser.getAttributeType(attributeCount)); attributeInfoVector.Add(attributeInfo); } parser.next(); // move to text, inner start tag or end tag Object result = null; String text = null; if (parser.getEventType() == XmlPullParser.TEXT) { text = parser.getText(); SoapPrimitive sp = new SoapPrimitive(typeNamespace, typeName, text); result = sp; // apply all the cached attribute info list before we add the property and descend further for parsing for (int i = 0; i < attributeInfoVector.Count; i++) { sp.addAttribute((AttributeInfo)attributeInfoVector[i]); } parser.next(); } else if (parser.getEventType() == XmlPullParser.END_TAG) { SoapObject so = new SoapObject(typeNamespace, typeName); // apply all the cached attribute info list before we add the property and descend further for parsing for (int i = 0; i < attributeInfoVector.Count; i++) { so.addAttribute((AttributeInfo)attributeInfoVector[i]); } result = so; } if (parser.getEventType() == XmlPullParser.START_TAG) { if (text != null && text.Trim().Length != 0) { throw new Exception("Malformed input: Mixed content"); } SoapObject so = new SoapObject(typeNamespace, typeName); // apply all the cached attribute info list before we add the property and descend further for parsing for (int i = 0; i < attributeInfoVector.Count; i++) { so.addAttribute((AttributeInfo)attributeInfoVector[i]); } while (parser.getEventType() != XmlPullParser.END_TAG) { so.addProperty(parser.getNamespace(), parser.getName(), read(parser, so, so.getPropertyCount(), null, null, PropertyInfo.OBJECT_TYPE)); parser.nextTag(); } result = so; } parser.require(XmlPullParser.END_TAG, namespace_, name); return(result); }
/** * Read a FvmSerializable. */ protected void readSerializable(XmlPullParser parser, FvmSerializable obj) { int tag = 0; try { tag = parser.nextTag(); } catch (XmlPullParserException e) { if (obj is HasInnerText) { ((HasInnerText)obj).setInnerText((parser.getText() != null) ? parser.getText() : ""); } tag = parser.nextTag(); } while (tag != XmlPullParser.END_TAG) { String name = parser.getName(); if (!implicitTypes || !(obj is SoapObject)) { PropertyInfo info = new PropertyInfo(); int propertyCount = obj.getPropertyCount(); bool propertyFound = false; for (int i = 0; i < propertyCount && !propertyFound; i++) { info.clear(); obj.getPropertyInfo(i, properties, info); if ((name.Equals(info.name) && info.namespace_ == null) || (name.Equals(info.name) && parser.getNamespace().Equals(info.namespace_))) { propertyFound = true; obj.setProperty(i, read(parser, obj, i, null, null, info)); } } if (!propertyFound) { if (avoidExceptionForUnknownProperty) { // Dummy loop to read until corresponding END tag while (parser.next() != XmlPullParser.END_TAG || !name.Equals(parser.getName())) { } ; } else { throw new Exception("Unknown Property: " + name); } } else { if (obj is HasAttributes) { HasAttributes soapObject = (HasAttributes)obj; int cnt = parser.getAttributeCount(); for (int counter = 0; counter < cnt; counter++) { AttributeInfo attributeInfo = new AttributeInfo(); attributeInfo.setName(parser.getAttributeName(counter)); attributeInfo.setValue(parser.getAttributeValue(counter)); attributeInfo.setNamespace(parser.getAttributeNamespace(counter)); attributeInfo.setType(parser.getAttributeType(counter)); soapObject.setAttribute(attributeInfo); } } } } else { // I can only make this work for SoapObjects - hence the check above // I don't understand namespaces well enough to know whether it is correct in the next line... ((SoapObject)obj).addProperty(parser.getName(), read(parser, obj, obj.getPropertyCount(), ((SoapObject)obj).getNamespace(), name, PropertyInfo.OBJECT_TYPE)); } try { tag = parser.nextTag(); } catch (XmlPullParserException e) { if (obj is HasInnerText) { ((HasInnerText)obj).setInnerText((parser.getText() != null) ? parser.getText() : ""); } tag = parser.nextTag(); } } parser.require(XmlPullParser.END_TAG, null, null); }
public virtual View inflate(XmlPullParser parser, ViewGroup root, bool attachToRoot) { //Trace.traceBegin(Trace.TRACE_TAG_VIEW, "inflate"); AttributeSet attrs = Xml.asAttributeSet(parser, mContext); Context lastContext = (Context)mConstructorArgs[0]; mConstructorArgs[0] = mContext; View result = root; try { // Look for the root node. int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { // Empty //"WHAT A MISTAKE!" - DJT; but this is how Android does it so we'll do it here :( } if (type != XmlPullParser.START_TAG) { throw new Exception(parser.getPositionDescription() + ": No start tag found!"); } string name = parser.getName(); if (DEBUG) { Debug.WriteLine("**************************"); Debug.WriteLine("Creating root view: " + name); Debug.WriteLine("**************************"); } if (TAG_MERGE.Equals(name)) { if (root == null || !attachToRoot) { throw new Exception("<merge /> can be used only with a valid " + "ViewGroup root and attachToRoot=true"); } rInflate(parser, root, attrs, false, false); } else { // Temp is the root view that was found in the xml View temp = createViewFromTag(root, name, attrs, false); ViewGroup.LayoutParams lparams = null; if (root != null) { if (DEBUG) { Debug.WriteLine("Creating params from root: " + root); } // Create layout params that match root, if supplied lparams = root.generateLayoutParams(attrs); if (!attachToRoot) { // Set the layout params for temp if we are not // attaching. (If we are, we use addView, below) temp.setLayoutParams(lparams); } } if (DEBUG) { Debug.WriteLine("-----> start inflating children"); } // Inflate all children under temp rInflate(parser, temp, attrs, true, true); if (DEBUG) { Debug.WriteLine("-----> done inflating children"); } // We are supposed to attach all the views we found (int temp) // to root. Do that now. if (root != null && attachToRoot) { root.addView(temp, lparams); } // Decide whether to return the root that was passed in or the // top view found in xml. if (root == null || !attachToRoot) { result = temp; } } } catch { throw; } finally { // Don't retain static reference on context. mConstructorArgs[0] = lastContext; mConstructorArgs[1] = null; } //Trace.traceEnd(Trace.TRACE_TAG_VIEW); return(result); }