Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Reading XML Node values (vb.net)

Posted on 2011-02-23
4
Medium Priority
?
432 Views
Last Modified: 2012-05-11
This is a sample of my config file

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

  <info>
        
    <Import timeOfDay="07:30" fileTypes="txt" sourceFolder="C:\Pending" destinationFolder="C:\Processed" logFilePath="log.txt" />
 
  </info>

</configuration>

There are lots of examples on how to get data from an XML file on the web, but my requirement is slightly different.

The key contains several values, how do I get each of them into local variables in my app.

If I could use the ConfigurationManager that would be great, but for now I'm resigned to just getting the data out.

Andy
0
Comment
Question by:Andy Green
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 34965241
By keys do you mean the attributes?
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 34965255
You mean you want to get the attributes of the "Import" node?

Try something like:
        Dim doc As New XmlDocument()
        doc.Load("Your xml file")

        Dim node As XmlNode = doc.SelectSingleNode("configuration/info/Import")

        Dim timeOfDay As String = node.Attributes("timeOfDay").InnerText
        Dim fileTypes As String = node.Attributes("fileTypes").InnerText

        '... etc, etc ....

Open in new window

0
 
LVL 17

Expert Comment

by:nepaluz
ID: 34965400
indeed you can use this too

        Dim StockDoc As XDocument = XDocument.Load("FullPathToYourFile.xml")
        Dim xtimeOfDay = From kp In StockDoc.Root.Descendants("Import") Select kp.@<timeOfDay>
        Dim xfileTypes = From kp In StockDoc.Root.Descendants Select kp.@<fileTypes>
        Dim xsourceFolder = From kp In StockDoc.Root.Descendants Select kp.@<sourceFolder>
        Dim xdestinationFolder = From kp In StockDoc.Root.Descendants Select kp.@<destinationFolder>
        Dim xlogFilePath = From kp In StockDoc.Root.Descendants Select kp.@<logFilePath>

Open in new window


The variables (lists) will include ALL attributes from ALL
Import

Open in new window

XElements sequentially.
0
 
LVL 3

Author Closing Comment

by:Andy Green
ID: 34965501
Great thank you

Andy
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

610 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