[Mono-list] Incompatibility in MONO SelectNodes method
Rafael Teixeira
rafael.teixeirabr at terra.com.br
Tue Dec 4 08:14:23 EST 2007
As a fan of generics I would create a helper class:
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
>
More information about the Mono-list
mailing list