Solved

Best way to phrase XML file

Posted on 2006-06-20
5
298 Views
Last Modified: 2011-10-03
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.

0
Comment
Question by:vpekulas
  • 3
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
rodmjay earned 500 total points
ID: 16946963
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
 
LVL 8

Expert Comment

by:rodmjay
ID: 16946975
excuse me that would be dim value as string =  xmldoc.getelementbyid("3").innertext
0
 

Author Comment

by:vpekulas
ID: 16947389
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
 

Author Comment

by:vpekulas
ID: 16947390
Nevermind, I got it :)
0
 

Author Comment

by:vpekulas
ID: 16948231
I take it back, this doesn't work without having to declare the XML structure.
I only have the XML as noted back.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question