diff options
author | Atsushi Eno <atsushieno@gmail.com> | 2005-12-14 18:59:23 +0300 |
---|---|---|
committer | Atsushi Eno <atsushieno@gmail.com> | 2005-12-14 18:59:23 +0300 |
commit | d4caf7151f21a0558b6007bf4525556ea6aeb9d3 (patch) | |
tree | 97caaf38ac821a3aa52e9527e5e49b14201b4c17 /mcs/class/System.XML | |
parent | cc5d84d39df0721dab3c1ab34a877b5fdaae326a (diff) |
2005-12-14 Atsushi Enomoto <atsushi@ximian.com>
* XPathNavigatorReader.cs : several fixes.
- Unless ReadState is Interactive, all name stuff should return "".
- Refactored Read() to work fine when input navigator is Root.
- Fixed all MoveTo*Attribute() methods match with other XmlReaders.
- Namespace nodes were not handled fine in MoveTo*Attribute().
* XPathNavigatorReaderTests.cs : new file for testing ReadSubtree()
and all dependent members.
* System.Xml_test.dll.sources: Added XPathNavigatorReaderTests.cs.
svn path=/trunk/mcs/; revision=54364
Diffstat (limited to 'mcs/class/System.XML')
6 files changed, 626 insertions, 70 deletions
diff --git a/mcs/class/System.XML/ChangeLog b/mcs/class/System.XML/ChangeLog index f3070f79e1a..7144b2383a6 100644 --- a/mcs/class/System.XML/ChangeLog +++ b/mcs/class/System.XML/ChangeLog @@ -1,3 +1,7 @@ +2005-12-14 Atsushi Enomoto <atsushi@ximian.com> + + * System.Xml_test.dll.sources: Added XPathNavigatorReaderTests.cs. + 2005-12-13 Atsushi Enomoto <atsushi@ximian.com> * System.Xml_test.dll.sources: Added XmlAssert.cs. diff --git a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog index 8078a7b4ae4..35fcc865ea5 100644 --- a/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog +++ b/mcs/class/System.XML/Mono.Xml.XPath/ChangeLog @@ -1,5 +1,13 @@ 2005-12-14 Atsushi Enomoto <atsushi@ximian.com> + * XPathNavigatorReader.cs : several fixes. + - Unless ReadState is Interactive, all name stuff should return "". + - Refactored Read() to work fine when input navigator is Root. + - Fixed all MoveTo*Attribute() methods match with other XmlReaders. + - Namespace nodes were not handled fine in MoveTo*Attribute(). + +2005-12-14 Atsushi Enomoto <atsushi@ximian.com> + * XPathEditableDocument.cs : added UnderlyingObject. 2005-12-14 Atsushi Enomoto <atsushi@ximian.com> diff --git a/mcs/class/System.XML/Mono.Xml.XPath/XPathNavigatorReader.cs b/mcs/class/System.XML/Mono.Xml.XPath/XPathNavigatorReader.cs index 5a5cf1f3f2c..273f3cb18a8 100644 --- a/mcs/class/System.XML/Mono.Xml.XPath/XPathNavigatorReader.cs +++ b/mcs/class/System.XML/Mono.Xml.XPath/XPathNavigatorReader.cs @@ -41,14 +41,13 @@ namespace Mono.Xml.XPath {
public XPathNavigatorReader (XPathNavigator nav)
{
- // It seems that this class have only to support linked
- // node as its parameter
switch (nav.NodeType) {
- case XPathNodeType.Attribute:
- case XPathNodeType.Namespace:
+ case XPathNodeType.Element:
+ case XPathNodeType.Root:
+ break;
+ default:
throw new InvalidOperationException (String.Format ("NodeType {0} is not supported to read as a subtree of an XPathNavigator.", nav.NodeType));
}
- root = nav.Clone ();
current = nav.Clone ();
}
@@ -66,7 +65,6 @@ namespace Mono.Xml.XPath int depth = 0;
int attributeCount = 0;
bool eof;
- bool nextIsEOF;
#region Properties
@@ -80,8 +78,7 @@ namespace Mono.Xml.XPath }
#endif
- public override XmlNodeType NodeType
- {
+ public override XmlNodeType NodeType {
get {
if (ReadState != ReadState.Interactive)
return XmlNodeType.None;
@@ -118,7 +115,9 @@ namespace Mono.Xml.XPath public override string Name {
get {
- if (eof)
+ if (ReadState != ReadState.Interactive)
+ return String.Empty;
+ if (attributeValueConsumed)
return String.Empty;
else if (current.NodeType == XPathNodeType.Namespace)
return current.Name == String.Empty ? "xmlns" : "xmlns:" + current.Name;
@@ -129,7 +128,9 @@ namespace Mono.Xml.XPath public override string LocalName {
get {
- if (eof)
+ if (ReadState != ReadState.Interactive)
+ return String.Empty;
+ if (attributeValueConsumed)
return String.Empty;
else if (current.NodeType == XPathNodeType.Namespace && current.LocalName == String.Empty)
return "xmlns";
@@ -140,7 +141,9 @@ namespace Mono.Xml.XPath public override string NamespaceURI {
get {
- if (eof)
+ if (ReadState != ReadState.Interactive)
+ return String.Empty;
+ if (attributeValueConsumed)
return String.Empty;
else if (current.NodeType == XPathNodeType.Namespace)
return "http://www.w3.org/2000/xmlns/";
@@ -151,7 +154,9 @@ namespace Mono.Xml.XPath public override string Prefix {
get {
- if (eof)
+ if (ReadState != ReadState.Interactive)
+ return String.Empty;
+ if (attributeValueConsumed)
return String.Empty;
else if (current.NodeType == XPathNodeType.Namespace && current.LocalName != String.Empty)
return "xmlns";
@@ -178,18 +183,21 @@ namespace Mono.Xml.XPath public override int Depth {
get {
- switch (ReadState) {
- case ReadState.EndOfFile:
- case ReadState.Initial:
- case ReadState.Closed:
+ if (ReadState != ReadState.Interactive)
return 0;
- }
+
+ if (NodeType == XmlNodeType.Attribute)
+ return depth + 1;
+ if (attributeValueConsumed)
+ return depth + 2;
return depth;
}
}
public override string Value {
get {
+ if (ReadState != ReadState.Interactive)
+ return String.Empty;
switch (current.NodeType) {
case XPathNodeType.Namespace:
case XPathNodeType.Attribute:
@@ -213,7 +221,11 @@ namespace Mono.Xml.XPath }
public override bool IsEmptyElement {
- get { return current.IsEmptyElement; }
+ get {
+ if (ReadState != ReadState.Interactive)
+ return false;
+ return current.IsEmptyElement;
+ }
}
public override bool IsDefault {
@@ -253,6 +265,8 @@ namespace Mono.Xml.XPath private int GetAttributeCount ()
{
+ if (ReadState != ReadState.Interactive)
+ return 0;
int count = 0;
if (current.MoveToFirstAttribute ()) {
do {
@@ -271,6 +285,8 @@ namespace Mono.Xml.XPath private bool MoveToAttributeNavigator (int i)
{
+ if (ReadState != ReadState.Interactive)
+ return false;
switch (current.NodeType) {
case XPathNodeType.Namespace:
case XPathNodeType.Attribute:
@@ -291,6 +307,7 @@ namespace Mono.Xml.XPath return false;
}
+ /*
public override string this [int i] {
get {
XPathNavigator backup = current.Clone ();
@@ -304,15 +321,23 @@ namespace Mono.Xml.XPath }
}
}
+ */
private void SplitName (string name, out string localName, out string ns)
{
+ if (name == "xmlns") {
+ localName = "xmlns";
+ ns = XmlNamespaceManager.XmlnsXmlns;
+ return;
+ }
localName = name;
ns = String.Empty;
int colon = name.IndexOf (':');
if (colon > 0) {
localName = name.Substring (colon + 1, name.Length - colon - 1);
ns = this.LookupNamespace (name.Substring (0, colon));
+ if (name.Substring (0, colon) == "xmlns")
+ ns = XmlNamespaceManager.XmlnsXmlns;
}
}
@@ -388,23 +413,39 @@ namespace Mono.Xml.XPath string localName;
string ns;
SplitName (name, out localName, out ns);
- return CheckAttributeMove (MoveToAttribute (localName, ns));
+ return MoveToAttribute (localName, ns);
}
public override bool MoveToAttribute (string localName, string namespaceURI)
{
+ bool isNS = namespaceURI == "http://www.w3.org/2000/xmlns/";
XPathNavigator backup = null;
switch (current.NodeType) {
+ case XPathNodeType.Namespace:
case XPathNodeType.Attribute:
backup = current.Clone ();
this.MoveToElement ();
goto case XPathNodeType.Element;
case XPathNodeType.Element:
- while (MoveToNextAttribute ())
- if (current.LocalName == localName && current.NamespaceURI == namespaceURI) {
- attributeValueConsumed = false;
- return true;
- }
+ if (MoveToFirstAttribute ()) {
+ do {
+ bool match = false;
+ if (isNS) {
+ if (localName == "xmlns")
+ match = current.Name == String.Empty;
+ else
+ match = localName == current.Name;
+ }
+ else
+ match = current.LocalName == localName &&
+ current.NamespaceURI == namespaceURI;
+ if (match) {
+ attributeValueConsumed = false;
+ return true;
+ }
+ } while (MoveToNextAttribute ());
+ MoveToElement ();
+ }
break;
}
if (backup != null)
@@ -412,32 +453,40 @@ namespace Mono.Xml.XPath return false;
}
+ /*
public override void MoveToAttribute (int i)
{
if (!MoveToAttributeNavigator (i))
throw new ArgumentOutOfRangeException ();
}
+ */
public override bool MoveToFirstAttribute ()
{
- bool b = CheckAttributeMove (current.MoveToFirstNamespace (XPathNamespaceScope.Local));
- if (b)
+ if (CheckAttributeMove (current.MoveToFirstNamespace (XPathNamespaceScope.Local)))
return true;
return CheckAttributeMove (current.MoveToFirstAttribute ());
}
public override bool MoveToNextAttribute ()
{
- if (current.NodeType == XPathNodeType.Namespace) {
- bool b = CheckAttributeMove (current.MoveToNextNamespace (XPathNamespaceScope.Local));
- if (b)
+ switch (current.NodeType) {
+ case XPathNodeType.Element:
+ return MoveToFirstAttribute ();
+ case XPathNodeType.Namespace:
+ if (CheckAttributeMove (current.MoveToNextNamespace (XPathNamespaceScope.Local)))
return true;
+ XPathNavigator bak = current.Clone ();
current.MoveToParent ();
- b = CheckAttributeMove (current.MoveToFirstAttribute ());
- if (b)
+ if (CheckAttributeMove (current.MoveToFirstAttribute ()))
return true;
+ current.MoveTo (bak);
+ return false;
+ case XPathNodeType.Attribute:
+ return CheckAttributeMove (current.MoveToNextAttribute ());
+ default:
+ return false;
}
- return CheckAttributeMove (current.MoveToNextAttribute ());
}
public override bool MoveToElement ()
@@ -458,66 +507,67 @@ namespace Mono.Xml.XPath public override bool Read ()
{
+ if (eof)
+ return false;
#if NET_2_0
if (Binary != null)
Binary.Reset ();
#endif
switch (ReadState) {
+ case ReadState.Interactive:
+ if ((IsEmptyElement || endElement) && root.IsSamePosition (current)) {
+ eof = true;
+ return false;
+ }
+ if (!current.IsEmptyElement && current.NodeType == XPathNodeType.Element)
+ depth++;
+ break;
case ReadState.EndOfFile:
case ReadState.Closed:
case ReadState.Error:
return false;
case ReadState.Initial:
started = true;
- switch (current.NodeType) {
- case XPathNodeType.Root:
- // recurse, but as Interactive
- return Read ();
- case XPathNodeType.Element:
- if (current.IsEmptyElement)
- nextIsEOF = true;
- attributeCount = GetAttributeCount ();
- return true;
- default:
- nextIsEOF = true;
- return true;
+ root = current.Clone ();
+ if (current.NodeType == XPathNodeType.Root &&
+ !current.MoveToFirstChild ()) {
+ endElement = false;
+ eof = true;
+ return false;
}
- break;
- }
-
- if (nextIsEOF) {
- nextIsEOF = false;
- eof = true;
- return false;
+ attributeCount = GetAttributeCount ();
+ return true;
}
MoveToElement ();
if (endElement || !current.MoveToFirstChild ()) {
- if (current.IsSamePosition (root)) { // It should happen only when the root node was empty.
- eof = true;
- return false;
- }
- if (!current.MoveToNext ()) {
+ // EndElement of current element.
+ if (!endElement && !current.IsEmptyElement &&
+ current.NodeType == XPathNodeType.Element)
+ endElement = true;
+ else if (!current.MoveToNext ()) {
current.MoveToParent ();
- depth--;
- endElement = (current.NodeType == XPathNodeType.Element);
- if (current.IsSamePosition (root)) {
- if (current.NodeType == XPathNodeType.Element)
- nextIsEOF = true;
- else {
- endElement = false;
- eof = true;
- return false;
- }
+ if (current.NodeType == XPathNodeType.Root) {
+ endElement = false;
+ eof = true;
+ return false;
}
- } else
+ endElement = (current.NodeType == XPathNodeType.Element);
+ }
+ else
endElement = false;
}
- else if (!endElement)
- depth++;
- attributeCount = GetAttributeCount ();
+
+ if (!endElement && current.NodeType == XPathNodeType.Element)
+ attributeCount = GetAttributeCount ();
+ else
+ attributeCount = 0;
+
+ if (endElement)
+ depth--;
+
return true;
}
diff --git a/mcs/class/System.XML/System.Xml_test.dll.sources b/mcs/class/System.XML/System.Xml_test.dll.sources index 2298eed97f4..3c9829f0edf 100644 --- a/mcs/class/System.XML/System.Xml_test.dll.sources +++ b/mcs/class/System.XML/System.Xml_test.dll.sources @@ -77,6 +77,7 @@ System.Xml.XPath/SelectNodesTests.cs System.Xml.XPath/XPathEditableNavigatorTests.cs System.Xml.XPath/XPathNavigatorEvaluateTests.cs System.Xml.XPath/XPathNavigatorMatchesTests.cs +System.Xml.XPath/XPathNavigatorReaderTests.cs System.Xml.XPath/XPathNavigatorTests.cs System.Xml.XPath/XPathNavigatorCommonTests.cs System.Xml.Xsl/XslTransformTests.cs diff --git a/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog b/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog index f607d14569b..f25f314e791 100644 --- a/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml.XPath/ChangeLog @@ -1,3 +1,8 @@ +2005-12-14 Atsushi Enomoto <atsushi@ximian.com> + + * XPathNavigatorReaderTests.cs : new file for testing ReadSubtree() + and all dependent members. + 2005-12-13 Atsushi Enomoto <atsushi@ximian.com> * XPathEditableNavigatorTests.cs : added tests for MoveToFollowing(). diff --git a/mcs/class/System.XML/Test/System.Xml.XPath/XPathNavigatorReaderTests.cs b/mcs/class/System.XML/Test/System.Xml.XPath/XPathNavigatorReaderTests.cs new file mode 100644 index 00000000000..f0ea6efafb5 --- /dev/null +++ b/mcs/class/System.XML/Test/System.Xml.XPath/XPathNavigatorReaderTests.cs @@ -0,0 +1,488 @@ +// +// MonoTests.System.Xml.XPathNavigatorReaderTests +// +// Author: +// Atsushi Enomoto <atsushi@ximian.com> +// +// Copyright (C) 2005 Novell, Inc. http://www.novell.com +// +#if NET_2_0 + +using System; +using System.Xml; +using System.Xml.XPath; +using NUnit.Framework; + +using MonoTests.System.Xml; // XmlAssert + +namespace MonoTests.System.Xml.XPath +{ + [TestFixture] + public class XPathNavigatorReaderTests + { + XmlDocument document; + XPathNavigator nav; + XPathDocument xpathDocument; + + [SetUp] + public void GetReady () + { + document = new XmlDocument (); + } + + private XPathNavigator GetXmlDocumentNavigator (string xml) + { + document.LoadXml (xml); + return document.CreateNavigator (); + } + + private XPathNavigator GetXPathDocumentNavigator (XmlNode node) + { + XmlNodeReader xr = new XmlNodeReader (node); + xpathDocument = new XPathDocument (xr); + return xpathDocument.CreateNavigator (); + } + + [Test] + public void ReadSubtree1 () + { + string xml = "<root/>"; + + nav = GetXmlDocumentNavigator (xml); + ReadSubtree1 (nav, "#1."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + ReadSubtree1 (nav, "#2."); + + nav = GetXPathDocumentNavigator (document); + ReadSubtree1 (nav, "#3."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + ReadSubtree1 (nav, "#4."); + } + + void ReadSubtree1 (XPathNavigator nav, string label) + { + XmlReader r = nav.ReadSubtree (); + + XmlAssert.AssertNode (label + "#1", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.None, 0, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsTrue (r.Read (), label + "#2"); + XmlAssert.AssertNode (label + "#3", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Element, 0, true, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsFalse (r.Read (), label + "#4"); + } + + [Test] + public void ReadSubtree2 () + { + string xml = "<root></root>"; + + nav = GetXmlDocumentNavigator (xml); + ReadSubtree2 (nav, "#1."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + ReadSubtree2 (nav, "#2."); + + nav = GetXPathDocumentNavigator (document); + ReadSubtree2 (nav, "#3."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + ReadSubtree2 (nav, "#4."); + } + + void ReadSubtree2 (XPathNavigator nav, string label) + { + XmlReader r = nav.ReadSubtree (); + + XmlAssert.AssertNode (label + "#1", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.None, 0, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsTrue (r.Read (), label + "#2"); + XmlAssert.AssertNode (label + "#3", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Element, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsTrue (r.Read (), label + "#4"); + XmlAssert.AssertNode (label + "#5", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.EndElement, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsFalse (r.Read (), label + "#6"); + } + + [Test] + public void ReadSubtree3 () + { + string xml = "<root attr='value'/>"; + + nav = GetXmlDocumentNavigator (xml); + ReadSubtree3 (nav, "#1."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + ReadSubtree3 (nav, "#2."); + + nav = GetXPathDocumentNavigator (document); + ReadSubtree3 (nav, "#3."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + ReadSubtree3 (nav, "#4."); + } + + void ReadSubtree3 (XPathNavigator nav, string label) + { + XmlReader r = nav.ReadSubtree (); + + XmlAssert.AssertNode (label + "#1", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.None, 0, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsTrue (r.Read (), label + "#2"); + XmlAssert.AssertNode (label + "#3", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Element, 0, true, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 1, true); + + Assert.IsTrue (r.MoveToFirstAttribute (), label + "#4"); + XmlAssert.AssertNode (label + "#5", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Attribute, 1, false, + // Name, Prefix, LocalName, NamespaceURI + "attr", String.Empty, "attr", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "value", true, 1, true); + + Assert.IsTrue (r.ReadAttributeValue (), label + "#6"); + XmlAssert.AssertNode (label + "#7", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Text, 2, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "value", true, 1, true); + + Assert.IsFalse (r.ReadAttributeValue (), label + "#8"); + Assert.IsFalse (r.MoveToNextAttribute (), label + "#9"); + Assert.IsTrue (r.MoveToElement (), label + "#10"); + + Assert.IsFalse (r.Read (), label + "#11"); + } + + [Test] + public void DocElem_OpenClose_Attribute () + { + string xml = "<root attr='value'></root>"; + + nav = GetXmlDocumentNavigator (xml); + DocElem_OpenClose_Attribute (nav, "#1."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + DocElem_OpenClose_Attribute (nav, "#2."); + + nav = GetXPathDocumentNavigator (document); + DocElem_OpenClose_Attribute (nav, "#3."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + DocElem_OpenClose_Attribute (nav, "#4."); + } + + void DocElem_OpenClose_Attribute (XPathNavigator nav, string label) + { + XmlReader r = nav.ReadSubtree (); + + XmlAssert.AssertNode (label + "#1", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.None, 0, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsTrue (r.Read (), label + "#2"); + XmlAssert.AssertNode (label + "#3", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Element, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 1, true); + + Assert.IsTrue (r.MoveToFirstAttribute (), label + "#4"); + XmlAssert.AssertNode (label + "#5", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Attribute, 1, false, + // Name, Prefix, LocalName, NamespaceURI + "attr", String.Empty, "attr", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "value", true, 1, true); + + Assert.IsTrue (r.ReadAttributeValue (), label + "#6"); + XmlAssert.AssertNode (label + "#7", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Text, 2, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "value", true, 1, true); + + Assert.IsFalse (r.ReadAttributeValue (), label + "#8"); + Assert.IsFalse (r.MoveToNextAttribute (), label + "#9"); + Assert.IsTrue (r.MoveToElement (), label + "#10"); + + Assert.IsTrue (r.Read (), label + "#11"); + XmlAssert.AssertNode (label + "#12", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.EndElement, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsFalse (r.Read (), label + "#13"); + } + + [Test] + public void FromChildElement () + { + string xml = "<root><foo attr='value'>test</foo><bar/></root>"; + + nav = GetXmlDocumentNavigator (xml); + nav.MoveToFirstChild (); + nav.MoveToFirstChild (); // foo + FromChildElement (nav, "#1."); + + nav = GetXPathDocumentNavigator (document); + nav.MoveToFirstChild (); + nav.MoveToFirstChild (); // foo + FromChildElement (nav, "#2."); + } + + void FromChildElement (XPathNavigator nav, string label) + { + XmlReader r = nav.ReadSubtree (); + + XmlAssert.AssertNode (label + "#1", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.None, 0, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsTrue (r.Read (), label + "#2"); + XmlAssert.AssertNode (label + "#3", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Element, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "foo", String.Empty, "foo", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 1, true); + + Assert.IsTrue (r.Read (), label + "#4"); + XmlAssert.AssertNode (label + "#5", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Text, 1, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "test", true, 0, false); + + Assert.IsTrue (r.Read (), label + "#6"); + XmlAssert.AssertNode (label + "#7", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.EndElement, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "foo", String.Empty, "foo", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + // end at </foo>, without moving toward <bar>. + Assert.IsFalse (r.Read (), label + "#8"); + } + + [Test] + public void AttributesAndNamespaces () + { + string xml = "<root attr='value' x:a2='v2' xmlns:x='urn:foo' xmlns='urn:default'></root>"; + + nav = GetXmlDocumentNavigator (xml); + AttributesAndNamespaces (nav, "#1."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + AttributesAndNamespaces (nav, "#2."); + + nav = GetXPathDocumentNavigator (document); + AttributesAndNamespaces (nav, "#3."); + + nav.MoveToRoot (); + nav.MoveToFirstChild (); + AttributesAndNamespaces (nav, "#4."); + } + + void AttributesAndNamespaces (XPathNavigator nav, string label) + { + XmlReader r = nav.ReadSubtree (); + + XmlAssert.AssertNode (label + "#1", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.None, 0, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsTrue (r.Read (), label + "#2"); + XmlAssert.AssertNode (label + "#3", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Element, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", "urn:default", + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 4, true); + + // Attributes + + Assert.IsTrue (r.MoveToAttribute ("attr"), label + "#14"); + XmlAssert.AssertNode (label + "#15", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Attribute, 1, false, + // Name, Prefix, LocalName, NamespaceURI + "attr", String.Empty, "attr", String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "value", true, 4, true); + + Assert.IsTrue (r.ReadAttributeValue (), label + "#16"); + XmlAssert.AssertNode (label + "#17", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Text, 2, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "value", true, 4, true); + + Assert.IsFalse (r.ReadAttributeValue (), label + "#18"); + + Assert.IsTrue (r.MoveToAttribute ("x:a2"), label + "#19"); + XmlAssert.AssertNode (label + "#20", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Attribute, 1, false, + // Name, Prefix, LocalName, NamespaceURI + "x:a2", "x", "a2", "urn:foo", + // Value, HasValue, AttributeCount, HasAttributes + "v2", true, 4, true); + + Assert.IsTrue (r.ReadAttributeValue (), label + "#21"); + XmlAssert.AssertNode (label + "#22", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Text, 2, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "v2", true, 4, true); + + // Namespaces + + Assert.IsTrue (r.MoveToAttribute ("xmlns"), label + "#9"); + XmlAssert.AssertNode (label + "#10", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Attribute, 1, false, + // Name, Prefix, LocalName, NamespaceURI + "xmlns", String.Empty, "xmlns", + "http://www.w3.org/2000/xmlns/", + // Value, HasValue, AttributeCount, HasAttributes + "urn:default", true, 4, true); + + Assert.IsTrue (r.ReadAttributeValue (), label + "#11"); +//* here too + XmlAssert.AssertNode (label + "#12", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Text, 2, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "urn:default", true, 4, true); +//*/ + + Assert.IsFalse (r.ReadAttributeValue (), label + "#13"); + + Assert.IsTrue (r.MoveToAttribute ("xmlns:x"), label + "#4"); + XmlAssert.AssertNode (label + "#5", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Attribute, 1, false, + // Name, Prefix, LocalName, NamespaceURI + "xmlns:x", "xmlns", "x", + "http://www.w3.org/2000/xmlns/", + // Value, HasValue, AttributeCount, HasAttributes + "urn:foo", true, 4, true); + + Assert.IsTrue (r.ReadAttributeValue (), label + "#6"); +///* temporarily comment out since MS.NET has a bug here + XmlAssert.AssertNode (label + "#7", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.Text, 2, false, + // Name, Prefix, LocalName, NamespaceURI + String.Empty, String.Empty, String.Empty, String.Empty, + // Value, HasValue, AttributeCount, HasAttributes + "urn:foo", true, 4, true); +//*/ + + Assert.IsFalse (r.ReadAttributeValue (), label + "#8"); + + Assert.IsTrue (r.MoveToElement (), label + "#24"); + + Assert.IsTrue (r.Read (), label + "#25"); + XmlAssert.AssertNode (label + "#26", r, + // NodeType, Depth, IsEmptyElement + XmlNodeType.EndElement, 0, false, + // Name, Prefix, LocalName, NamespaceURI + "root", String.Empty, "root", "urn:default", + // Value, HasValue, AttributeCount, HasAttributes + String.Empty, false, 0, false); + + Assert.IsFalse (r.Read (), label + "#27"); + } + } +} + +#endif |