Re: LINQ to XML to Find Escaped Ampersand Problems?
Hi SnapDive,
Yes, you are correct! Forcing large sized XML document, we can combine
XmlReader and LINQ to XML to query the XML data, so as to decrease the
memory cost. For detail, please refer to the following code snippet:
================================================================
using (XmlReader reader = XmlReader.Create("MyXml.xml"))
{
reader.MoveToContent();
while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element)
{
if (reader.Name == "subpart")
{
XElement ele = XElement.ReadFrom(reader) as XElement;
if (ele != null)
{
var query = from element in ele.DescendantNodesAndSelf()
where element.NodeType == System.Xml.XmlNodeType.CDATA
let CDataElement = element as XCData
where CDataElement.Value.Contains("&")
select CDataElement;
foreach (var q in query)
{
MessageBox.Show(q.Value);
}
}
}
}
}
}
================================================================
For some additional references, please see
http://blogs.msdn.com/xmlteam/archive/2007/03/24/streaming-with-linq-to-xml-
part-2.aspx &
http://james.newtonking.com/archive/2007/12/11/linq-to-xml-over-large-docume
nts.aspx.
If you have any questions, please feel free to let me know.
Have a nice day!
Regards,
Lingzhi Sun
Microsoft Online Community Support
=================================================
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.
This posting is provided "AS IS" with no warranties, and confers no rights.
=================================================