int GetAttributeIndex(string name, string ns) { if (attributes == null) { return(-1); } for (int i = 0; i < attributes.Count; i++) { if (AXmlObject.GetLocalName(attributes[i].Name) == name && (LookupNamespace(AXmlObject.GetNamespacePrefix(attributes[i].Name)) ?? string.Empty) == ns) { return(i); } } return(-1); }
bool ReadCurrentPosition() { attributes = null; attributeIndex = -1; inAttributeValue = false; while (true) { var obj = objectIterator.CurrentObject; if (obj == null) { readState = ReadState.EndOfFile; elementNodeType = XmlNodeType.None; return(false); } else if (objectIterator.IsAtElementEnd) { if (IsEmptyElement) { // Don't report EndElement for empty elements nsManager.PopScope(); } else { elementNodeType = XmlNodeType.EndElement; return(true); } } else if (obj is InternalElement) { // element start elementNodeType = XmlNodeType.Element; InternalTag startTag = ((InternalTag)obj.NestedObjects[0]); nsManager.PushScope(); if (startTag.NestedObjects != null) { attributes = startTag.NestedObjects.OfType <InternalAttribute>().ToList(); for (int i = 0; i < attributes.Count; i++) { var attr = attributes[i]; if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal)) { nsManager.AddNamespace(AXmlObject.GetLocalName(attr.Name), attr.Value); } else if (attr.Name == "xmlns") { nsManager.AddNamespace(string.Empty, attr.Value); } } } return(true); } else if (obj is InternalText) { InternalText text = (InternalText)obj; if (text.ContainsOnlyWhitespace) { elementNodeType = XmlNodeType.Whitespace; } else { elementNodeType = XmlNodeType.Text; } return(true); } else if (obj is InternalTag) { InternalTag tag = (InternalTag)obj; if (tag.IsStartOrEmptyTag || tag.IsEndTag) { // start/end tags can be skipped as the parent InternalElement already handles them } else if (tag.IsComment && !settings.IgnoreComments) { elementNodeType = XmlNodeType.Comment; return(true); } else if (tag.IsProcessingInstruction && !settings.IgnoreProcessingInstructions) { if (tag.Name == "xml") { elementNodeType = XmlNodeType.XmlDeclaration; attributes = tag.NestedObjects.OfType <InternalAttribute>().ToList(); } else { elementNodeType = XmlNodeType.ProcessingInstruction; } return(true); } else if (tag.IsCData) { elementNodeType = XmlNodeType.CDATA; return(true); } else { // TODO all other tags } } else { throw new NotSupportedException(); } objectIterator.MoveInto(); } }