5 // Copyright 2007 Novell (http://www.novell.com)
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Xml.Linq;
31 using System.Xml.XPath;
33 using NUnit.Framework;
35 namespace MonoTests.System.Xml.Linq
38 public class XNodeNavigatorTest
41 public void MoveToNext ()
43 XElement a = new XElement ("root",
46 XPathNavigator nav = a.CreateNavigator ();
47 Assert.IsTrue (nav.MoveToFirstChild (), "#1");
48 Assert.IsTrue (nav.MoveToNext (), "#2");
52 [ExpectedException (typeof (NotSupportedException))]
53 public void MoveToId () // ID is not supported here.
59 <!ATTLIST foo id ID #IMPLIED>
60 <!ATTLIST bar id ID #IMPLIED>
62 <root><foo id='foo' /><bar id='bar' /></root>";
63 XDocument doc = XDocument.Parse (xml, LoadOptions.SetLineInfo);
64 XPathNavigator nav = doc.CreateNavigator ();
69 public void Bug594877 ()
71 string data = "<rt> <objsur t=\"o\" guid=\"06974d9a-ff86-4e1c-a3e5-7ce8c961dcb9\" /> </rt>";
72 XElement xeOldOwner = XElement.Parse(data);
73 string xpathOld = String.Format(".//objsur[@t='o']");
74 XElement xeOldRef = xeOldOwner.XPathSelectElement(xpathOld);
75 Assert.AreEqual ("<objsur t='o' guid='06974d9a-ff86-4e1c-a3e5-7ce8c961dcb9' />".Replace ('\'', '"'), xeOldRef.ToString (), "#1");
79 public void Bug4739 ()
81 string data = "<root><parent>A<child>B</child>C</parent></root>";
82 XElement doc = XElement.Parse (data);
83 var iterator = doc.CreateNavigator ().Select ("//parent/child");
85 var element = iterator.Current;
86 Assert.AreEqual ("B", element.InnerXml);
90 public void MoveToRoot_Bug4690 ()
92 string data = "<root><parent><child/></parent></root>";
93 XElement doc = XElement.Parse (data);
94 var iterator = doc.CreateNavigator ().Select ("//child");
96 var element = iterator.Current;
97 element.MoveToRoot ();
98 Assert.AreEqual ("root", element.Name);