diff options
Diffstat (limited to 'mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs')
-rw-r--r-- | mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs | 95 |
1 files changed, 45 insertions, 50 deletions
diff --git a/mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs b/mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs index 15f75ee4eb0..b2ee93599a8 100644 --- a/mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs +++ b/mcs/class/System.XML/System.Xml/XmlDocumentNavigator.cs @@ -88,13 +88,10 @@ namespace System.Xml if (NsNode != null) return false; - XmlElement el = node as XmlElement; - if (el == null || !el.HasAttributes) - return false; - - for (int i = 0; i < node.Attributes.Count; i++) - if (node.Attributes [i].NamespaceURI != Xmlns) - return true; + if (node.Attributes != null) + for (int i = 0; i < node.Attributes.Count; i++) + if (node.Attributes [i].NamespaceURI != Xmlns) + return true; return false; } } @@ -357,12 +354,15 @@ namespace System.Xml public override bool MoveToAttribute (string localName, string namespaceURI) { - if (HasAttributes) { - XmlAttribute attr = node.Attributes [localName, namespaceURI]; - if (attr != null) { - node = attr; - NsNode = null; - return true; + if (node.Attributes != null) { + for (int i = 0; i < node.Attributes.Count; i++) { + XmlAttribute attr = node.Attributes [i]; + if (attr.LocalName == localName + && attr.NamespaceURI == namespaceURI) { + node = attr; + NsNode = null; + return true; + } } } return false; @@ -378,10 +378,9 @@ namespace System.Xml public override bool MoveToFirstAttribute () { + if (node.Attributes == null) + return false; if (NodeType == XPathNodeType.Element) { - XmlElement el = node as XmlElement; - if (!el.HasAttributes) - return false; for (int i = 0; i < node.Attributes.Count; i++) { XmlAttribute attr = node.Attributes [i]; if (attr.NamespaceURI != Xmlns) { @@ -411,8 +410,8 @@ namespace System.Xml if (NodeType != XPathNodeType.Element) return false; XmlElement el = node as XmlElement; - do { - if (el.HasAttributes) { + if (node.Attributes != null) { + do { for (int i = 0; i < el.Attributes.Count; i++) { XmlAttribute attr = el.Attributes [i]; if (attr.NamespaceURI == Xmlns) { @@ -422,11 +421,11 @@ namespace System.Xml return true; } } - } - if (namespaceScope == XPathNamespaceScope.Local) - return false; - el = GetParentNode (el) as XmlElement; - } while (el != null); + if (namespaceScope == XPathNamespaceScope.Local) + return false; + el = GetParentNode (el) as XmlElement; + } while (el != null); + } if (namespaceScope == XPathNamespaceScope.All) { if (CheckNsNameAppearance (nsNodeXml.Name, nsNodeXml.Value)) @@ -459,8 +458,8 @@ namespace System.Xml return false; XmlElement el = node as XmlElement; - do { - if (el.HasAttributes) { + if (node.Attributes != null) { + do { for (int i = 0; i < el.Attributes.Count; i++) { XmlAttribute attr = el.Attributes [i]; if (attr.NamespaceURI == Xmlns && attr.Name == name) { @@ -468,9 +467,9 @@ namespace System.Xml return true; } } - } - el = GetParentNode (node) as XmlElement; - } while (el != null); + el = GetParentNode (node) as XmlElement; + } while (el != null); + } return false; } @@ -575,15 +574,13 @@ namespace System.Xml return false; owner = GetParentNode (owner) as XmlElement; while (owner != null) { - if (owner.HasAttributes) { - for (int i = 0; i < owner.Attributes.Count; i++) { - XmlAttribute attr = owner.Attributes [i]; - if (attr.NamespaceURI == Xmlns) { - if (CheckNsNameAppearance (attr.Name, attr.Value)) - continue; - NsNode = attr; - return true; - } + for (int i = 0; i < owner.Attributes.Count; i++) { + XmlAttribute attr = owner.Attributes [i]; + if (attr.NamespaceURI == Xmlns) { + if (CheckNsNameAppearance (attr.Name, attr.Value)) + continue; + NsNode = attr; + return true; } } owner = GetParentNode (owner) as XmlElement; @@ -699,20 +696,19 @@ namespace System.Xml private XmlNode GetPreviousSibling (XmlNode n) { - XmlNode p = n.PreviousSibling; - if (p != null) { - switch (p.NodeType) { + if (n.PreviousSibling != null) { + switch (n.PreviousSibling.NodeType) { case XmlNodeType.EntityReference: - XmlNode c = GetLastChild (p); + XmlNode c = GetLastChild (n.PreviousSibling); if (c != null) return c; else // empty entity reference etc. - return GetPreviousSibling (p); + return GetPreviousSibling (n.PreviousSibling); case XmlNodeType.XmlDeclaration: case XmlNodeType.DocumentType: - return GetPreviousSibling (p); + return GetPreviousSibling (n.PreviousSibling); default: - return p; + return n.PreviousSibling; } } else { if (n.ParentNode == null || n.ParentNode.NodeType != XmlNodeType.EntityReference) @@ -723,18 +719,17 @@ namespace System.Xml private XmlNode GetNextSibling (XmlNode n) { - XmlNode nx = n.NextSibling; - if (nx != null) { - switch (nx.NodeType) { + if (n.NextSibling != null) { + switch (n.NextSibling.NodeType) { case XmlNodeType.EntityReference: - XmlNode c = GetFirstChild (nx); + XmlNode c = GetFirstChild (n.NextSibling); if (c != null) return c; else // empty entity reference etc. - return GetNextSibling (nx); + return GetNextSibling (n.NextSibling); case XmlNodeType.XmlDeclaration: case XmlNodeType.DocumentType: - return GetNextSibling (nx); + return GetNextSibling (n.NextSibling); default: return n.NextSibling; } |