// Authors:
// Jason Diamond <jason@injektilo.org>
// Martin Willemoes Hansen <mwh@sysrq.dk>
+// Atsushi Enomoto <atsushi@ximian.com>
//
// (C) 2002 Jason Diamond
// (C) 2003 Martin Willemoes Hansen
+// (C) 2004-2006 Novell, Inc.
//
using System;
}
}
+ [Test]
+ public void TextMatchesWhitespace ()
+ {
+ string xml = "<root><ws> </ws><sws xml:space='preserve'> </sws></root>";
+ XmlDocument doc = new XmlDocument ();
+ doc.PreserveWhitespace = true;
+ doc.LoadXml (xml);
+ XPathNavigator nav = doc.CreateNavigator ();
+ nav.MoveToFirstChild (); // root
+ nav.MoveToFirstChild (); // ws
+ nav.MoveToFirstChild (); // ' '
+ AssertEquals ("#1", true, nav.Matches ("text()"));
+ nav.MoveToParent ();
+ nav.MoveToNext (); // sws
+ nav.MoveToFirstChild (); // ' '
+ AssertEquals ("#2", true, nav.Matches ("text()"));
+ }
+
#if NET_2_0
[Test]
public void ValueAsBoolean ()
iter.MoveNext ();
AssertEquals ("val"1 >", iter.Current.InnerXml);
}
+
+ [Test]
+ public void WriterAttributePrefix ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ XmlWriter w = doc.CreateNavigator ().AppendChild ();
+ w.WriteStartElement ("foo");
+ w.WriteAttributeString ("xmlns", "x", "http://www.w3.org/2000/xmlns/", "urn:foo");
+ AssertEquals ("#0", "x", w.LookupPrefix ("urn:foo"));
+ w.WriteStartElement (null, "bar", "urn:foo");
+ w.WriteAttributeString (null, "ext", "urn:foo", "bah");
+ w.WriteEndElement ();
+ w.WriteEndElement ();
+ w.Close ();
+ AssertEquals ("#1", "x", doc.FirstChild.FirstChild.Prefix);
+ AssertEquals ("#2", "x", doc.FirstChild.FirstChild.Attributes [0].Prefix);
+ }
+
+ [Test]
+ public void ValueAs ()
+ {
+ string xml = "<root>1</root>";
+ XPathNavigator nav = new XPathDocument (XmlReader.Create (new StringReader (xml))).CreateNavigator ();
+ nav.MoveToFirstChild ();
+ nav.MoveToFirstChild ();
+ AssertEquals ("1", nav.ValueAs (typeof (string), null));
+ AssertEquals (1, nav.ValueAs (typeof (int), null));
+ }
+
+ [Test]
+ public void MoveToFollowingNodeTypeAll ()
+ {
+ XmlDocument doc = new XmlDocument ();
+ doc.LoadXml ("<root><child/><child2/></root>");
+ XPathNavigator nav = doc.CreateNavigator ();
+ Assert ("#1", nav.MoveToFollowing (XPathNodeType.All));
+ Assert ("#2", nav.MoveToFollowing (XPathNodeType.All));
+ AssertEquals ("#3", "child", nav.LocalName);
+ Assert ("#4", nav.MoveToNext (XPathNodeType.All));
+ AssertEquals ("#5", "child2", nav.LocalName);
+ }
+
+ [Test] // bug #324606.
+ public void XPathDocumentFromSubtreeNodes ()
+ {
+ string xml = "<root><child1><nest1><nest2>hello!</nest2></nest1></child1><child2/><child3/></root>";
+ XmlReader r = new XmlTextReader (new StringReader (xml));
+ while (r.Read ()) {
+ if (r.Name == "child1")
+ break;
+ }
+ XPathDocument d = new XPathDocument (r);
+ XPathNavigator n = d.CreateNavigator ();
+ string result = @"<child1>
+ <nest1>
+ <nest2>hello!</nest2>
+ </nest1>
+</child1>
+<child2 />
+<child3 />";
+ AssertEquals (result, n.OuterXml.Replace ("\r\n", "\n"));
+ }
+
+ [Test] // bug #376191
+ public void InnerXmlOnRoot ()
+ {
+ XmlDocument document = new XmlDocument ();
+ document.LoadXml (@"<test>
+ <node>z</node>
+ <node>a</node>
+ <node>b</node>
+ <node>q</node>
+ </test>");
+ XPathNavigator navigator = document.CreateNavigator();
+ AssertEquals (navigator.OuterXml, navigator.InnerXml);
+ }
#endif
}
}