Link to home
Start Free TrialLog in
Avatar of Andy Green
Andy GreenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Reading XML Node values (vb.net)

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
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

By keys do you mean the attributes?
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of Andy Green

ASKER

Great thank you

Andy