navigating a CACHED XML file...how?

  • Thread starter Thread starter darrel
  • Start date Start date
D

darrel

I can navigate an XML file to find a particular value as such:

Dim xpd As System.Xml.XPath.XPathDocument = New
System.Xml.XPath.XPathDocument(XMLfile)
Dim xpn As System.Xml.XPath.XPathNavigator = xpd.CreateNavigator()

and then I create an expression and navigate to the value I want.

I'm now wanting to cache this file. To do so, I read in the file, and then
set that string to the cache object:

Dim file As New
System.IO.StreamReader(HttpContext.Current.Server.MapPath("myfile.xml")
XMLfile = file.ReadToEnd
file.Close()
(set the cache object to this string).

The problem in doing that is that my XPD is now a string...not a reference
to a file. It appears that an XPathDocument needs to reference a physical
file, rather than the cached XML data itself.

I'm stuck as to what I need to do to make this work. Do I need to use
something other than an XPathDocument?

-Darrel
 
darrel said:
The problem in doing that is that my XPD is now a string...not a reference
to a file. It appears that an XPathDocument needs to reference a physical
file, rather than the cached XML data itself.

Darrel,

All you have to do is take the XML string back out of the Cache and load
it into the XPathDocument using a StringReader, like this,

Dim sr As System.IO.StringReader
sr = New System.IO.StringReader( strXmlData)
Dim xpd As System.Xml.XPath.XPathDocument
xpd = New XPathDocument( sr)

and you can create an XPathNavigator from this XPD the same as if it had
been created from a file.


Derek Harmon
 
All you have to do is take the XML string back out of the Cache and load
it into the XPathDocument using a StringReader, like this,

Dim sr As System.IO.StringReader
sr = New System.IO.StringReader( strXmlData)
Dim xpd As System.Xml.XPath.XPathDocument
xpd = New XPathDocument( sr)

and you can create an XPathNavigator from this XPD the same as if it had
been created from a file.

Derek:

Wonderful! That works great. Thanks!

-Darrel
 
Back
Top