[Mono-list] Incompatibility in MONO SelectNodes method

Robert Jordan robertj at gmx.net
Tue Dec 4 09:21:36 EST 2007


Rafael Teixeira wrote:
> As a fan of generics I would create a helper class:


In such cases I'm using a non-generic "generic" isolator:

using System;
using System.Collections;

public class Isolator : IEnumerable
{
	IEnumerable inner;

	public Isolator (IEnumerable enumerable)
	{
		inner = enumerable;
	}

	public IEnumerator GetEnumerator ()
	{
		ArrayList list = new ArrayList ();
		foreach (object o in inner)
			list.Add (o);
		return list.GetEnumerator ();
	}
}

Then I use it this way:

  	XmlNodeList list = xDoc.SelectNodes("//comment()");
  	foreach (XmlNode node in new Isolator (list))
  		node.ParentNode.RemoveChild(node);


Robert

> 
> public class XmlNodeListHelper
> {
> 	public static List<XmlNode> CopyNodeList(XmlNodeList list)
> 	{
> 		List<XmlNode> copy = new List<XmlNode>();
> 	 
> 	 	foreach (XmlNode node in list)
> 	 		copy.Add (node);
> 	 		
> 	 	return copy;
> 	}
> 
> 	public static void RemoveNodes(XmlNodeList list)
> 	{
> 	 	foreach (XmlNode node in CopyNodeList(list))
> 	 		node.ParentNode.RemoveChild(node); 
> 	}
> }
> 
> And so the code in question would become just:
> 
> XmlNodeListHelper.RemoveNodes(xDoc.SelectNodes("//comment()"));
> 
> When using the latest compilers it could be made into a Mono.Rocks
> helper like:
> 
> public class XmlNodeListHelper
> {
> 	public static List<XmlNode> CopyAsList(this XmlNodeList list)
> 	{
> 		List<XmlNode> copy = new List<XmlNode>();
> 	 
> 	 	foreach (XmlNode node in list)
> 	 		copy.Add (node);
> 	 		
> 	 	return copy;
> 	}
> 
> 	public static void RemoveNodes(this XmlNodeList list)
> 	{
> 	 	foreach (XmlNode node in list.CopyAsList())
> 	 		node.ParentNode.RemoveChild(node); 
> 	}
> }
> 
> And then usage would be even simpler
> 
> Doc.SelectNodes("//comment()").RemoveNodes();
> 
> Just my two cents, 
> 
> On Sun, 2007-12-02 at 03:29 +0100, Robert Jordan wrote:
>> Andrus wrote:
>>> In bug #343960
>>>
>>> https://bugzilla.novell.com/show_bug.cgi?id=343960
>>>
>>> I presented code which works OK in .NET  but crashes in MONO 1.2.6 pvw2.
>>> Probably SelectNodes() in .NET creates new list but in MONO it does not.
>>> Atsushi refuses to fix this and marks it INVALID several times.
>> He explained pretty well why he refused to fix it.
>>
>>> This is fundamental incompatibility between .NET and MONO XML DOM 
>>> implementation.
>> Come on!
>>
>>> Is it really reasonable not to fix this ?
>>>
>>> How to change this code so it works in MONO also ? 
>> 	XmlNodeList list = xDoc.SelectNodes("//comment()");
>> 	ArrayList temp = new ArrayList ();
>>
>> 	foreach (XmlNode node in list)
>> 		temp.Add (node);
>> 	
>> 	foreach (XmlNode node in temp)
>> 		node.ParentNode.RemoveChild(node);
>>
>> Robert
>>
> 
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list
> 



More information about the Mono-list mailing list