Thanks Oleg.
I also like your input on the use of XmlTextReader. In this case, my xml
data is really small, so it really doesn't matter. However, if I were to
use XmlTextReader for something significantly larger, how would I select a
particular node?
I love xpath expressions and I'm hooked on it! I'm concerned that using
XmlTextReader means that I need to iterate through node after node until I
find the node I am looking for. Is there a way to use xpath with something
like XmlTextReader?
Thanks again!
Jiho
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Jiho Han wrote:
I have the following code:
// code start
string resultValue;
XmlTextReader xtReader = new XmlTextReader(dataXml, XmlNodeType.Element,
null);
XPathDocument xpDoc = new XPathDocument(xtReader);
XPathNodeIterator iterator = xpDoc.CreateNavigator().Select("//result");
while(iterator.MoveNext())
{
resultValue = iterator.Current.Value;
break;
}
return resultValue;
// code end
Is there something that I can do to help clean up any resources right
away or do I just wait for the GC?
It the code really ends here (so XPathDocument isn't referenced
anymore), do nothing, GC will take care.
Btw, using XmlTextReader directly you could save some memory avoiding
XPathDocument, which loads the whole XML document into memory.
--
Oleg Tkachenko [XML MVP, XmlInsider]
http://blog.tkachenko.com