Solved

Best way to phrase XML file

Posted on 2006-06-20
5
296 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now