From 9c85aff822b610999c1e6271fb5535e0769f203c Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Tue, 27 Jan 2004 09:40:23 +0000 Subject: [PATCH] 2004-01-27 Atsushi Enomoto * DTMXPathDocumentBuilder.cs : Namespace nodes are incorrectly created. This fix should make XPathDocument compatible with XmlDocument. svn path=/trunk/mcs/; revision=22529 --- mcs/class/System.XML/Mono.Xml.XPath/ChangeLog | 5 +++ .../Mono.Xml.XPath/DTMXPathDocumentBuilder.cs | 36 +++++++++---------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog index 385f4169cf3..56504699f70 100644 --- a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog +++ b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog @@ -1,3 +1,8 @@ +2004-01-27 Atsushi Enomoto + + * DTMXPathDocumentBuilder.cs : Namespace nodes are incorrectly created. + This fix should make XPathDocument compatible with XmlDocument. + 2004-01-26 Atsushi Enomoto * DTMXPathDocument.cs : CreateNavigator() should return the first root diff --git a/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder.cs b/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder.cs index 8e021d948b8..5989f2c1658 100644 --- a/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder.cs +++ b/mcs/class/System.XML/Mono.Xml.XPath/DTMXPathDocumentBuilder.cs @@ -83,6 +83,7 @@ namespace Mono.Xml.XPath int prevSibling; int position; + int lastNsInScope; bool skipRead = false; public DTMXPathDocument CreateDocument () @@ -116,6 +117,7 @@ namespace Mono.Xml.XPath AddNode (0, 0, 0, 0, -1, 0, XPathNodeType.Root, xmlReader.BaseURI, false, "", "", "", "", "", 1, 0, 0); this.nodeIndex = 1; + this.lastNsInScope = 1; this.requireFirstChildFill = true; while (!xmlReader.EOF) @@ -232,6 +234,9 @@ namespace Mono.Xml.XPath int firstAttributeIndex = 0; int lastNsIndexInCurrent = 0; + while (namespaces [lastNsInScope].DeclaredElement == previousSibling) { + lastNsInScope = namespaces [lastNsInScope].NextNamespace; + } // process namespaces and attributes. if (xmlReader.MoveToFirstAttribute ()) { @@ -247,8 +252,6 @@ namespace Mono.Xml.XPath "" : xmlReader.LocalName, xmlReader.Value); namespaces [nsIndex].NextNamespace = nextTmp; -// if (lastNsIndexInCurrent == 0) -// nodes [nodeIndex].FirstNamespace = nsIndex; lastNsIndexInCurrent = nsIndex; } else { // add attribute node. @@ -284,6 +287,9 @@ namespace Mono.Xml.XPath xmlReader.MoveToElement (); } + if (lastNsIndexInCurrent > 0) + lastNsInScope = nsIndex; + AddNode (parent, firstAttributeIndex, attributeIndex, @@ -298,7 +304,7 @@ namespace Mono.Xml.XPath xmlReader.Prefix, "", // Element has no internal value. xmlReader.XmlLang, - nsIndex, + lastNsInScope, lineInfo != null ? lineInfo.LineNumber : 0, lineInfo != null ? lineInfo.LinePosition : 0); if (!xmlReader.IsEmptyElement) @@ -332,13 +338,11 @@ namespace Mono.Xml.XPath public void AddNode (int parent, int firstAttribute, int attributeEnd, int previousSibling, int depth, int position, XPathNodeType nodeType, string baseUri, bool isEmptyElement, string localName, string ns, string prefix, string value, string xmlLang, int namespaceNode, int lineNumber, int linePosition) { if (nodes.Length < nodeIndex + 1) { -// if (nodes.Length >= nodeCapacity) { - nodeCapacity *= 2; - SetNodeArrayLength (nodeCapacity); -// } + nodeCapacity *= 2; + SetNodeArrayLength (nodeCapacity); } - DTMXPathLinkedNode curNode = nodes [nodeIndex];// = new DTMXPathLinkedNode (); + DTMXPathLinkedNode curNode = nodes [nodeIndex]; nodes [nodeIndex].FirstChild = 0; // dummy nodes [nodeIndex].Parent = parent; nodes [nodeIndex].FirstAttribute = firstAttribute; @@ -363,13 +367,11 @@ namespace Mono.Xml.XPath public void AddAttribute (int ownerElement, string localName, string ns, string prefix, string value, object schemaType, int lineNumber, int linePosition) { if (attributes.Length < attributeIndex + 1) { -// if (attributes.Length >= attributeCapacity) { - attributeCapacity *= 2; - SetAttributeArrayLength (attributeCapacity); -// } + attributeCapacity *= 2; + SetAttributeArrayLength (attributeCapacity); } - DTMXPathAttributeNode attr = attributes [attributeIndex];// = new DTMXPathAttributeNode (); + DTMXPathAttributeNode attr = attributes [attributeIndex]; attributes [attributeIndex].OwnerElement = ownerElement; attributes [attributeIndex].LocalName = localName; attributes [attributeIndex].NamespaceURI = ns; @@ -384,13 +386,11 @@ namespace Mono.Xml.XPath public void AddNsNode (int declaredElement, string name, string ns) { if (namespaces.Length < nsIndex + 1) { -// if (namespaces.Length >= nsCapacity) { - nsCapacity *= 2; - SetNsArrayLength (nsCapacity); -// } + nsCapacity *= 2; + SetNsArrayLength (nsCapacity); } - DTMXPathNamespaceNode nsNode = namespaces [nsIndex];// = new DTMXPathNamespaceNode (); + DTMXPathNamespaceNode nsNode = namespaces [nsIndex]; namespaces [nsIndex].DeclaredElement = declaredElement; namespaces [nsIndex].Name = name; namespaces [nsIndex].Namespace = ns; -- 2.25.1