XmlNodeTests.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. //
  2. // System.Xml.XmlNodeTests
  3. //
  4. // Authors:
  5. // Kral Ferch <[email protected]>
  6. // Martin Willemoes Hansen
  7. //
  8. // (C) 2002 Kral Ferch
  9. // (C) 2003 Martin Willemoes Hansen
  10. //
  11. using System;
  12. using System.IO;
  13. using System.Text;
  14. using System.Xml;
  15. using NUnit.Framework;
  16. using MonoTests.Helpers;
  17. namespace MonoTests.System.Xml
  18. {
  19. [TestFixture]
  20. public class XmlNodeTests
  21. {
  22. XmlDocument document;
  23. XmlElement element;
  24. XmlElement element2;
  25. bool inserted;
  26. bool inserting;
  27. bool changed;
  28. bool changing;
  29. bool removed;
  30. bool removing;
  31. [SetUp]
  32. public void GetReady ()
  33. {
  34. document = new XmlDocument ();
  35. document.NodeInserted += new XmlNodeChangedEventHandler (this.EventNodeInserted);
  36. document.NodeInserting += new XmlNodeChangedEventHandler (this.EventNodeInserting);
  37. document.NodeRemoved += new XmlNodeChangedEventHandler (this.EventNodeRemoved);
  38. document.NodeRemoving += new XmlNodeChangedEventHandler (this.EventNodeRemoving);
  39. element = document.CreateElement ("foo");
  40. element2 = document.CreateElement ("bar");
  41. }
  42. private void EventNodeInserted(Object sender, XmlNodeChangedEventArgs e)
  43. {
  44. inserted = true;
  45. }
  46. private void EventNodeInserting (Object sender, XmlNodeChangedEventArgs e)
  47. {
  48. inserting = true;
  49. }
  50. private void EventNodeChanged(Object sender, XmlNodeChangedEventArgs e)
  51. {
  52. changed = true;
  53. }
  54. private void EventNodeChanging (Object sender, XmlNodeChangedEventArgs e)
  55. {
  56. changing = true;
  57. }
  58. private void EventNodeRemoved(Object sender, XmlNodeChangedEventArgs e)
  59. {
  60. removed = true;
  61. }
  62. private void EventNodeRemoving (Object sender, XmlNodeChangedEventArgs e)
  63. {
  64. removing = true;
  65. }
  66. [Test]
  67. public void AppendChild ()
  68. {
  69. XmlComment comment;
  70. inserted = false;
  71. inserting = false;
  72. element.AppendChild (element2);
  73. Assert.IsTrue (inserted);
  74. Assert.IsTrue (inserting);
  75. // Can only append to elements, documents, and attributes
  76. try
  77. {
  78. comment = document.CreateComment ("baz");
  79. comment.AppendChild (element2);
  80. Assert.Fail ("Expected an InvalidOperationException to be thrown.");
  81. }
  82. catch (InvalidOperationException) {}
  83. // Can't append a node from one document into another document.
  84. XmlDocument document2 = new XmlDocument();
  85. Assert.AreEqual (1, element.ChildNodes.Count);
  86. try
  87. {
  88. element2 = document2.CreateElement ("qux");
  89. element.AppendChild (element2);
  90. Assert.Fail ("Expected an ArgumentException to be thrown.");
  91. }
  92. catch (ArgumentException) {}
  93. Assert.AreEqual (1, element.ChildNodes.Count);
  94. // Can't append to a readonly node.
  95. /* TODO put this in when I figure out how to create a read-only node.
  96. try
  97. {
  98. XmlElement element3 = (XmlElement)element.CloneNode (false);
  99. Assert.IsTrue (!element.IsReadOnly);
  100. Assert.IsTrue (element3.IsReadOnly);
  101. element2 = document.CreateElement ("quux");
  102. element3.AppendChild (element2);
  103. Assert.Fail ("Expected an ArgumentException to be thrown.");
  104. }
  105. catch (ArgumentException) {}
  106. */
  107. }
  108. [Test]
  109. public void GetNamespaceOfPrefix ()
  110. {
  111. document.LoadXml ("<root xmlns='urn:default' attr='value' "
  112. + "xml:lang='en' xmlns:foo='urn:foo' foo:att='fooatt'>text node</root>");
  113. XmlNode n = document.DocumentElement;
  114. Assert.AreEqual ("urn:default", n.GetNamespaceOfPrefix (String.Empty), "#1");
  115. Assert.AreEqual ("urn:foo", n.GetNamespaceOfPrefix ("foo"), "#2");
  116. Assert.AreEqual (String.Empty, n.GetNamespaceOfPrefix ("bar"), "#3");
  117. Assert.AreEqual ("http://www.w3.org/XML/1998/namespace", n.GetNamespaceOfPrefix ("xml"), "#4");
  118. Assert.AreEqual ("http://www.w3.org/2000/xmlns/", n.GetNamespaceOfPrefix ("xmlns"), "#5");
  119. n = document.DocumentElement.FirstChild;
  120. Assert.AreEqual ("urn:default", n.GetNamespaceOfPrefix (String.Empty), "#6");
  121. Assert.AreEqual ("urn:foo", n.GetNamespaceOfPrefix ("foo"), "#7");
  122. Assert.AreEqual (String.Empty, n.GetNamespaceOfPrefix ("bar"), "#8");
  123. Assert.AreEqual ("http://www.w3.org/XML/1998/namespace", n.GetNamespaceOfPrefix ("xml"), "#9");
  124. Assert.AreEqual ("http://www.w3.org/2000/xmlns/", n.GetNamespaceOfPrefix ("xmlns"), "#10");
  125. }
  126. [Test]
  127. [ExpectedException (typeof (ArgumentNullException))]
  128. public void GetNamespaceOfPrefixNullArg ()
  129. {
  130. new XmlDocument ().GetNamespaceOfPrefix (null);
  131. }
  132. [Test]
  133. public void InsertBefore()
  134. {
  135. document = new XmlDocument();
  136. document.LoadXml("<root><sub /></root>");
  137. XmlElement docelem = document.DocumentElement;
  138. docelem.InsertBefore(document.CreateElement("good_child"), docelem.FirstChild);
  139. Assert.AreEqual ("good_child", docelem.FirstChild.Name, "InsertBefore.Normal");
  140. // These are required for .NET 1.0 but not for .NET 1.1.
  141. try {
  142. document.InsertBefore (document.CreateElement ("BAD_MAN"), docelem);
  143. Assert.Fail ("#InsertBefore.BadPositionButNoError.1");
  144. }
  145. catch (Exception) {}
  146. }
  147. [Test]
  148. public void InsertAfter()
  149. {
  150. document = new XmlDocument();
  151. document.LoadXml("<root><sub1 /><sub2 /></root>");
  152. XmlElement docelem = document.DocumentElement;
  153. XmlElement newelem = document.CreateElement("good_child");
  154. docelem.InsertAfter(newelem, docelem.FirstChild);
  155. Assert.AreEqual (3, docelem.ChildNodes.Count, "InsertAfter.Normal");
  156. Assert.AreEqual ("sub1", docelem.FirstChild.Name, "InsertAfter.First");
  157. Assert.AreEqual ("sub2", docelem.LastChild.Name, "InsertAfter.Last");
  158. Assert.AreEqual ("good_child", docelem.FirstChild.NextSibling.Name, "InsertAfter.Prev");
  159. Assert.AreEqual ("good_child", docelem.LastChild.PreviousSibling.Name, "InsertAfter.Next");
  160. // this doesn't throw any exception *only on .NET 1.1*
  161. // .NET 1.0 throws an exception.
  162. try {
  163. document.InsertAfter(document.CreateElement("BAD_MAN"), docelem);
  164. #if USE_VERSION_1_1
  165. Assert.AreEqual ("<root><sub1 /><good_child /><sub2 /></root><BAD_MAN />", document.InnerXml, "InsertAfter with bad location");
  166. } catch (XmlException ex) {
  167. throw ex;
  168. }
  169. #else
  170. } catch (Exception) {}
  171. #endif
  172. }
  173. [Test]
  174. public void Normalize ()
  175. {
  176. XmlDocument doc = new XmlDocument ();
  177. doc.LoadXml ("<root>This is the <b>hardest</b> one.</root>");
  178. doc.NodeInserted += new XmlNodeChangedEventHandler (EventNodeInserted);
  179. doc.NodeChanged += new XmlNodeChangedEventHandler (EventNodeChanged);
  180. doc.NodeRemoved += new XmlNodeChangedEventHandler (EventNodeRemoved);
  181. Assert.AreEqual (3, doc.DocumentElement.ChildNodes.Count);
  182. doc.DocumentElement.Normalize ();
  183. Assert.AreEqual (3, doc.DocumentElement.ChildNodes.Count);
  184. Assert.IsTrue (changed);
  185. inserted = changed = removed = false;
  186. doc.DocumentElement.AppendChild (doc.CreateTextNode ("Addendum."));
  187. Assert.AreEqual (4, doc.DocumentElement.ChildNodes.Count);
  188. inserted = changed = removed = false;
  189. doc.DocumentElement.Normalize ();
  190. Assert.AreEqual (3, doc.DocumentElement.ChildNodes.Count);
  191. Assert.IsTrue (changed);
  192. Assert.IsTrue (removed);
  193. inserted = changed = removed = false;
  194. doc.DocumentElement.SetAttribute ("attr", "");
  195. XmlAttribute attr = doc.DocumentElement.Attributes [0] as XmlAttribute;
  196. Assert.AreEqual (1, attr.ChildNodes.Count);
  197. inserted = changed = removed = false;
  198. attr.Normalize ();
  199. // Such behavior violates DOM Level 2 Node#normalize(),
  200. // but MS DOM is designed as such.
  201. Assert.AreEqual (1, attr.ChildNodes.Count);
  202. }
  203. [Test]
  204. public void Normalize2 ()
  205. {
  206. XmlDocument doc = new XmlDocument ();
  207. doc.PreserveWhitespace = true;
  208. doc.LoadXml ("<root> </root>");
  209. XmlElement root = doc.DocumentElement;
  210. root.AppendChild (doc.CreateTextNode ("foo"));
  211. root.AppendChild (doc.CreateTextNode ("bar"));
  212. root.AppendChild (doc.CreateWhitespace (" "));
  213. root.AppendChild (doc.CreateTextNode ("baz"));
  214. doc.NodeInserted += new XmlNodeChangedEventHandler (OnChange);
  215. doc.NodeChanged += new XmlNodeChangedEventHandler (OnChange);
  216. doc.NodeRemoved += new XmlNodeChangedEventHandler (OnChange);
  217. Assert.AreEqual (5, root.ChildNodes.Count, "Before Normalize()");
  218. root.Normalize ();
  219. Assert.AreEqual ("<root> foobar baz</root>", root.OuterXml);
  220. Assert.AreEqual (1, root.ChildNodes.Count, "After Normalize()");
  221. }
  222. int normalize2Count;
  223. private void OnChange (object o, XmlNodeChangedEventArgs e)
  224. {
  225. switch (normalize2Count) {
  226. case 0:
  227. Assert.AreEqual (XmlNodeChangedAction.Remove, e.Action, "Action0");
  228. Assert.AreEqual (" ", e.Node.Value, "Value0");
  229. break;
  230. case 1:
  231. Assert.AreEqual (XmlNodeChangedAction.Remove, e.Action, "Action1");
  232. Assert.AreEqual ("bar", e.Node.Value, "Value1");
  233. break;
  234. case 2:
  235. Assert.AreEqual (XmlNodeChangedAction.Remove, e.Action, "Action2");
  236. Assert.AreEqual (" ", e.Node.Value, "Value2");
  237. break;
  238. case 3:
  239. Assert.AreEqual (XmlNodeChangedAction.Remove, e.Action, "Action3");
  240. Assert.AreEqual ("baz", e.Node.Value, "Value3");
  241. break;
  242. case 4:
  243. Assert.AreEqual (XmlNodeChangedAction.Change, e.Action, "Action4");
  244. Assert.AreEqual (" foobar baz", e.Node.Value, "Value4");
  245. break;
  246. default:
  247. Assert.Fail (String.Format ("Unexpected event. Action = {0}, node type = {1}, node name = {2}, node value = {3}", e.Action, e.Node.NodeType, e.Node.Name, e.Node.Value));
  248. break;
  249. }
  250. normalize2Count++;
  251. }
  252. [Test]
  253. public void PrependChild()
  254. {
  255. document = new XmlDocument();
  256. document.LoadXml("<root><sub1 /><sub2 /></root>");
  257. XmlElement docelem = document.DocumentElement;
  258. docelem.PrependChild(document.CreateElement("prepender"));
  259. Assert.AreEqual ("prepender", docelem.FirstChild.Name, "PrependChild");
  260. }
  261. public void saveTestRemoveAll ()
  262. {
  263. // TODO: put this test back in when AttributeCollection.RemoveAll() is implemented.
  264. element.AppendChild(element2);
  265. removed = false;
  266. removing = false;
  267. element.RemoveAll ();
  268. Assert.IsTrue (removed);
  269. Assert.IsTrue (removing);
  270. }
  271. [Test]
  272. public void RemoveChild ()
  273. {
  274. element.AppendChild(element2);
  275. removed = false;
  276. removing = false;
  277. element.RemoveChild (element2);
  278. Assert.IsTrue (removed);
  279. Assert.IsTrue (removing);
  280. }
  281. [Test]
  282. public void RemoveLastChild ()
  283. {
  284. element.InnerXml = "<foo/><bar/><baz/>";
  285. element.RemoveChild (element.LastChild);
  286. Assert.IsNotNull (element.FirstChild);
  287. }
  288. [Test]
  289. public void GetPrefixOfNamespace ()
  290. {
  291. document.LoadXml ("<root><c1 xmlns='urn:foo'><c2 xmlns:foo='urn:foo' xmlns='urn:bar'><c3 xmlns=''/></c2></c1></root>");
  292. Assert.AreEqual (String.Empty, document.DocumentElement.GetPrefixOfNamespace ("urn:foo"), "root");
  293. Assert.AreEqual (String.Empty, document.DocumentElement.GetPrefixOfNamespace ("urn:foo"), "c1");
  294. Assert.AreEqual (String.Empty, document.DocumentElement.FirstChild.GetPrefixOfNamespace ("urn:foo"), "c2");
  295. Assert.AreEqual ("foo", document.DocumentElement.FirstChild.FirstChild.GetPrefixOfNamespace ("urn:foo"), "c3");
  296. // disconnected nodes.
  297. XmlNode n = document.CreateElement ("foo");
  298. Assert.AreEqual (String.Empty, n.GetPrefixOfNamespace ("foo"));
  299. n = document.CreateTextNode ("text"); // does not have Attributes
  300. Assert.AreEqual (String.Empty, n.GetPrefixOfNamespace ("foo"));
  301. n = document.CreateXmlDeclaration ("1.0", null, null); // does not have Attributes
  302. Assert.AreEqual (String.Empty, n.GetPrefixOfNamespace ("foo"));
  303. }
  304. [Test]
  305. public void GetPrefixOfNamespace2 ()
  306. {
  307. XmlDocument doc = new XmlDocument ();
  308. doc.AppendChild (doc.CreateElement ("foo"));
  309. doc.DocumentElement.SetAttributeNode (
  310. doc.CreateAttribute ("xmlns", "u", "http://www.w3.org/2000/xmlns/"));
  311. doc.DocumentElement.Attributes [0].Value = "urn:foo";
  312. XmlElement el = doc.CreateElement ("bar");
  313. doc.DocumentElement.AppendChild (el);
  314. Assert.AreEqual ("u", el.GetPrefixOfNamespace ("urn:foo"));
  315. }
  316. [Test]
  317. public void ReplaceChild ()
  318. {
  319. document.LoadXml ("<root/>");
  320. document.NodeInserted += new XmlNodeChangedEventHandler (this.EventNodeInserted);
  321. document.NodeChanged += new XmlNodeChangedEventHandler (this.EventNodeChanged);
  322. document.NodeRemoved += new XmlNodeChangedEventHandler (this.EventNodeRemoved);
  323. inserted = changed = removed = false;
  324. XmlElement el = document.CreateElement("root2");
  325. document.ReplaceChild (el, document.DocumentElement);
  326. Assert.AreEqual ("root2", document.DocumentElement.Name);
  327. Assert.AreEqual (1, document.ChildNodes.Count);
  328. Assert.IsTrue (inserted && removed && !changed);
  329. }
  330. [Test]
  331. public void InnerText ()
  332. {
  333. document.LoadXml ("<root>This is <b>mixed</b> content. Also includes <![CDATA[CDATA section]]>.<!-- Should be ignored --></root>");
  334. string total = "This is mixed content. Also includes CDATA section.";
  335. XmlNode elemB = document.DocumentElement.ChildNodes [1];
  336. Assert.AreEqual ("mixed", elemB.FirstChild.InnerText); // text node
  337. Assert.AreEqual ("mixed", elemB.InnerText); // element b
  338. Assert.AreEqual (total, document.DocumentElement.InnerText); // element root
  339. Assert.AreEqual (total, document.InnerText); // whole document
  340. }
  341. [Test]
  342. public void InnerXmlWithXmlns ()
  343. {
  344. XmlDocument document = new XmlDocument ();
  345. XmlElement xel = document.CreateElement ("KeyValue", "http://www.w3.org/2000/09/xmldsig#");
  346. xel.SetAttribute ("xmlns", "http://www.w3.org/2000/09/xmldsig#");
  347. xel.InnerXml = "<DSAKeyValue>blablabla</DSAKeyValue>";
  348. string expected = "<KeyValue xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><DSAKeyValue>blablabla</DSAKeyValue></KeyValue>";
  349. Assert.AreEqual (expected, xel.OuterXml);
  350. }
  351. [Test]
  352. public void SelectNodes ()
  353. {
  354. // This test is done in this class since it tests only XmlDocumentNavigator.
  355. string xpath = "//@*|//namespace::*";
  356. XmlDocument doc = new XmlDocument ();
  357. doc.LoadXml ("<element xmlns='urn:foo'><foo><bar>test</bar></foo></element>");
  358. XmlNodeList nl = doc.SelectNodes (xpath);
  359. Assert.AreEqual (6, nl.Count);
  360. // BTW, as for namespace nodes, Node does not exist
  361. // in the tree, so the return value should be
  362. // implementation dependent.
  363. Assert.AreEqual (XmlNodeType.Attribute, nl [0].NodeType, "#1");
  364. Assert.AreEqual (XmlNodeType.Attribute, nl [1].NodeType, "#2");
  365. Assert.AreEqual (XmlNodeType.Attribute, nl [2].NodeType, "#3");
  366. Assert.AreEqual (XmlNodeType.Attribute, nl [3].NodeType, "#4");
  367. Assert.AreEqual (XmlNodeType.Attribute, nl [4].NodeType, "#5");
  368. Assert.AreEqual (XmlNodeType.Attribute, nl [5].NodeType, "#6");
  369. Assert.AreEqual ("xmlns", nl [0].LocalName);
  370. Assert.AreEqual ("xml", nl [1].LocalName);
  371. Assert.AreEqual ("xmlns", nl [2].LocalName);
  372. Assert.AreEqual ("xml", nl [3].LocalName);
  373. Assert.AreEqual ("xmlns", nl [4].LocalName);
  374. Assert.AreEqual ("xml", nl [5].LocalName);
  375. }
  376. [Test]
  377. [Ignore ("MS.NET has a bug; it does not return nodes in document order.")]
  378. public void SelectNodes2 ()
  379. {
  380. // This test is done in this class since it tests only XmlDocumentNavigator.
  381. string xpath = "//*|//@*|//namespace::*";
  382. XmlDocument doc = new XmlDocument ();
  383. doc.LoadXml ("<element xmlns='urn:foo'><foo><bar>test</bar></foo></element>");
  384. XmlNodeList nl = doc.SelectNodes (xpath);
  385. Assert.AreEqual (9, nl.Count);
  386. Assert.AreEqual (XmlNodeType.Element, nl [0].NodeType);
  387. Assert.AreEqual (XmlNodeType.Attribute, nl [1].NodeType);
  388. Assert.AreEqual (XmlNodeType.Attribute, nl [2].NodeType);
  389. Assert.AreEqual (XmlNodeType.Element, nl [3].NodeType);
  390. Assert.AreEqual (XmlNodeType.Attribute, nl [4].NodeType);
  391. Assert.AreEqual (XmlNodeType.Attribute, nl [5].NodeType);
  392. Assert.AreEqual (XmlNodeType.Element, nl [6].NodeType);
  393. Assert.AreEqual (XmlNodeType.Attribute, nl [7].NodeType);
  394. Assert.AreEqual (XmlNodeType.Attribute, nl [8].NodeType);
  395. Assert.AreEqual ("element", nl [0].LocalName);
  396. Assert.AreEqual ("xmlns", nl [1].LocalName);
  397. Assert.AreEqual ("xml", nl [2].LocalName);
  398. Assert.AreEqual ("foo", nl [3].LocalName);
  399. Assert.AreEqual ("xmlns", nl [4].LocalName);
  400. Assert.AreEqual ("xml", nl [5].LocalName);
  401. Assert.AreEqual ("bar", nl [6].LocalName);
  402. Assert.AreEqual ("xmlns", nl [7].LocalName);
  403. Assert.AreEqual ("xml", nl [8].LocalName);
  404. }
  405. [Test]
  406. public void BaseURI ()
  407. {
  408. // See bug #64120.
  409. XmlDocument doc = new XmlDocument ();
  410. doc.Load (TestResourceHelper.GetFullPathOfResource ("Test/XmlFiles/simple.xml"));
  411. XmlElement el = doc.CreateElement ("foo");
  412. Assert.AreEqual (String.Empty, el.BaseURI);
  413. doc.DocumentElement.AppendChild (el);
  414. Assert.IsTrue (String.Empty != el.BaseURI);
  415. XmlAttribute attr = doc.CreateAttribute ("attr");
  416. Assert.AreEqual (String.Empty, attr.BaseURI);
  417. }
  418. [Test]
  419. public void CloneReadonlyNode ()
  420. {
  421. // Clone() should return such node that is not readonly
  422. string dtd = "<!DOCTYPE root ["
  423. + "<!ELEMENT root (#PCDATA|foo)*>"
  424. + "<!ELEMENT foo EMPTY>"
  425. + "<!ENTITY ent1 '<foo /><![CDATA[cdata]]>'>]>";
  426. string xml = dtd + "<root>&ent1;</root>";
  427. XmlDocument doc = new XmlDocument ();
  428. doc.LoadXml (xml);
  429. XmlNode n = doc.DocumentElement.FirstChild.FirstChild;
  430. Assert.IsTrue (n.IsReadOnly, "#1");
  431. Assert.IsTrue (!n.CloneNode (true).IsReadOnly, "#2");
  432. }
  433. [Test] // bug #80233
  434. public void InnerTextComment ()
  435. {
  436. XmlDocument doc = new XmlDocument ();
  437. doc.LoadXml ("<a><!--xx--></a>");
  438. Assert.AreEqual (String.Empty, doc.InnerText);
  439. }
  440. [Test] // part of bug #80331
  441. public void AppendReferenceChildAsNewChild ()
  442. {
  443. XmlDocument d = new XmlDocument ();
  444. XmlElement r = d.CreateElement ("Docs");
  445. d.AppendChild (r);
  446. XmlElement s = Create (d, "param", "pattern");
  447. s.AppendChild (Create (d, "para", "insert text here"));
  448. r.AppendChild (s);
  449. r.AppendChild (Create (d, "param", "pattern"));
  450. r.AppendChild (Create (d, "param", "pattern"));
  451. r.InsertBefore (s, r.FirstChild);
  452. }
  453. XmlElement Create (XmlDocument d, string name, string param)
  454. {
  455. XmlElement e = d.CreateElement (name);
  456. e.SetAttribute ("name", param);
  457. return e;
  458. }
  459. [Test] // bug #80331
  460. public void PrependChild2 ()
  461. {
  462. XmlDocument d = new XmlDocument ();
  463. XmlElement r = d.CreateElement ("Docs");
  464. d.AppendChild (r);
  465. XmlElement s = Create (d, "param", "pattern");
  466. s.AppendChild (Create (d, "para", "insert text here"));
  467. r.AppendChild (s);
  468. r.AppendChild (Create (d, "param", "pattern"));
  469. r.AppendChild (Create (d, "param", "pattern"));
  470. r.PrependChild (s);
  471. }
  472. }
  473. }