CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Read From XML

  1. #1
    Join Date
    Apr 2003
    Location
    New Jersey
    Posts
    28

    Question Read From XML

    Hi All

    I want to read a particular data from an XML
    e.g in the XML given below From node Services
    I want to read value for Path or Frequency.

    <Services>
    <Path>E:\Attach2\ISE\TCG\</Path>
    <Frequency>120</Frequency>
    <LogFilePath>G:\TLOG\ISE\Test.txt</LogFilePath>
    <FileExtn>.xls</FileExtn>
    <Application>Mock2</Application>
    </Services>

    How to achieve this in VB.Net?

    Last edited by Kate_For_U; May 2nd, 2003 at 12:35 AM.

  2. #2
    Join Date
    Jan 2003
    Location
    Amsterdam, Netherlands
    Posts
    97
    Easiest is to read your xml file into a dataset.

    Code:
            Dim path As String
            Dim ds As New System.Data.DataSet
    
            ds.ReadXml("your xml file.xml")
    
            path = ds.Tables("Services").Rows(0).Item("Path").ToString
    Danny
    Last edited by DdH; May 2nd, 2003 at 03:41 AM.

  3. #3
    Join Date
    Apr 2003
    Location
    New Jersey
    Posts
    28
    The use of dataset can be done , but then this would add one more object.

    Isn't there an inbuilt feature of .Net to do this.

  4. #4
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167
    Look at SYSTEM.XML namespace. The steps should be:
    1. Use XMLDOCUMENT object to read that XML string/file
    2. Use SelectSingleNode() method of XMLDOCUMENT object to get the node (PATH or FREQUENCY) that you want.
    3. Use Text property (i think that is the property that holds TEXT value for XMLNODE) to get the value of that node.

    -Cool Bizs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured