navigating a CACHED XML file...how?

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
 
D

Derek Harmon

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
 
D

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:

Wonderful! That works great. Thanks!

-Darrel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top