Best way to phrase XML file

I have a XML file with the following structure:

<?xml version="1.0" encoding="utf-8" ?>
<root>
      <content>
            <item id="1"><![CDATA[ The value 1 goes here ]]></item>
            <item id="2"><![CDATA[ The value 2 goes here ]]></item>
            <item id="3"><![CDATA[ The value 3 goes here ]]></item>
            <item id="4"><![CDATA[ The value 4 goes here ]]></item>
      </content>      
</root>


What's the best way to phrase the file in order to get the value
for item id say 3 ?

I'll be making a lot of hits for the file, so ideally the read
would be from cache. Any example you can provide would be greatly
appreciated. Thanks.


I work with VB.NET on .NET 2.0.

vpekulasAsked:
Who is Participating?
 
rodmjayCommented:
Probably the xmlDocument.GetElementbyID method would work the best

Here is code that does what you want

dim xmldoc as new xmldocument

dim value as string = xmldoc.getelementbyid("3")

http://msdn2.microsoft.com/en-us/library/system.xml.xmldocument.getelementbyid.aspx
0
 
rodmjayCommented:
excuse me that would be dim value as string =  xmldoc.getelementbyid("3").innertext
0
 
vpekulasAuthor Commented:
OK, that looks promising, now how do I cache the read (not look-up) so I don't have
to open the xml file each and every time ?
0
 
vpekulasAuthor Commented:
Nevermind, I got it :)
0
 
vpekulasAuthor Commented:
I take it back, this doesn't work without having to declare the XML structure.
I only have the XML as noted back.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.