C
C#13mo ago
SiloCitizen3

XMl: How to convert IEnumerable<XmlNode> to XmlNodeList ?

XMl: How to convert IEnumerable<XmlNode> to XmlNodeList ?
6 Replies
viceroypenguin
viceroypenguin13mo ago
you can't. but you can go the opposite way and get an IEnumerable<XmlNode> from an XmlNodeList by doing:
XmlNodeList list;
list.OfType<XmlNode>()
XmlNodeList list;
list.OfType<XmlNode>()
SiloCitizen3
SiloCitizen3OP13mo ago
so I essentially am forced into doing this whole crap?
var xmlDoc = new XDocument(new XElement("Root",
myIEnumerableListOfXmlNode.Select(node => XElement.Parse(node.OuterXml))));

var xmlDocument = new XmlDocument();
using (var xmlReader = xmlDoc.CreateReader())
{
xmlDocument.Load(xmlReader);
}
return xmlDocument.SelectNodes("//Root/*");
var xmlDoc = new XDocument(new XElement("Root",
myIEnumerableListOfXmlNode.Select(node => XElement.Parse(node.OuterXml))));

var xmlDocument = new XmlDocument();
using (var xmlReader = xmlDoc.CreateReader())
{
xmlDocument.Load(xmlReader);
}
return xmlDocument.SelectNodes("//Root/*");
?
viceroypenguin
viceroypenguin13mo ago
¯\_(ツ)_/¯ I don't use the old XmlNode stuff. it's the first draft that belongs in net1.0 and barely net2.0. XDocument and XNode are the better technologies regardless. unless you're dealing with a really old library that requires XmlNode, I'd torch anythign that touches XmlNode
SiloCitizen3
SiloCitizen3OP13mo ago
unless you're dealing with a really old library that requires XmlNode yeah, that's the hole i'm in ;_; thank you!
viceroypenguin
viceroypenguin13mo ago
name and shame! haha if it's public, we might be able to give you info on a better one if it's not public, then yeah, you're hosed
Matt Warren
Matt Warren13mo ago
XmlNode came out before generics were in C#. It was also tied to attempt to match the spec for xml document from W3C, and is burdened by a need to act as a mutable structure with events. XDocument came out with LINQ and was unbound by other constraints.
Want results from more Discord servers?
Add your server