private void WriteAttribute(XmlWriter writer, XmlAttribute attribute, List <StyleResource> styleResources) { if (ParsingHelper.IsXmlOnlyAttribute(attribute)) { WriteSpecificAttribute(writer, attribute, styleResources); } else { if (!string.IsNullOrWhiteSpace(attribute.NamespaceUri)) { string namespaceUri = attribute.NamespaceUri; string localName = attribute.LocalName; string namespaceName = attribute.FullName.Split(':')[0]; if (_nsDictionary.ContainsKey(namespaceUri)) { namespaceName = _nsDictionary[namespaceUri]; } else { _nsDictionary.Add(namespaceUri, namespaceName); } writer.WriteAttributeString(namespaceName, localName, namespaceUri, attribute.Value); } else { writer.WriteAttributeString(attribute.FullName, attribute.Value); } } }
private void _ExtractExpressions(XmlElement element, List <XmlAttribute> expressionAttributes, List <IdViewObject> viewsId) { if (ParsingHelper.IsResourceTag(element)) { //will be processed later so do not touch it for now return; } string id = null; bool isFragment = ParsingHelper.IsFragmentTag(element); List <XmlAttribute> bindings = new List <XmlAttribute>(); foreach (XmlAttribute attribute in element.Attributes) { if (ParsingHelper.IsXmlOnlyAttribute(attribute)) { continue; } if (ParsingHelper.IsIdAttribute(attribute)) { if (id != null) { throw new Exception("Multiple id for same element"); } id = attribute.Value; // add @+id/ to use auto declare mechanism in Android attribute.Value = "@+id/" + id; //check isFragment cause we will do a findViewById next and it will not works if (!isFragment) { viewsId.Add(new IdViewObject(element.LocalName, id)); } } else if (ParsingHelper.IsCustomAttribute(attribute)) { bindings.Add(attribute); } else if (ParsingHelper.IsAttributeWithExpression(attribute)) { bindings.Add(attribute); } } if (id == null && bindings.Any()) { XmlAttribute attribute = new XmlAttribute(); id = NameGeneratorHelper.GetViewId(); attribute.Value = "@+id/" + id; attribute.FullName = "android:id"; attribute.NamespaceUri = "http://schemas.android.com/apk/res/android"; element.Attributes.Add(attribute); //check isFragment cause we will do a findViewById next and it will not works if (!isFragment) { viewsId.Add(new IdViewObject(element.LocalName, id)); } } foreach (XmlAttribute attribute in bindings) { attribute.AttachedId = id; element.Attributes.Remove(attribute); } expressionAttributes.AddRange(bindings); foreach (XmlElement child in element.Children) { _ExtractExpressions(child, expressionAttributes, viewsId); } }