Results 1 to 2 of 2

Thread: [RESOLVED] get values from xml elements

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Location
    San Marcos, TX
    Posts
    177

    Resolved [RESOLVED] get values from xml elements

    Here's a portion of my xml file

    <sources>
    <comicbooks>
    <source>
    <profile>0</profile>
    <name>Main</name>
    <path>*mypath not showing*</path>
    </source>
    </comicbooks>
    </sources>

    I am also using a schema file for the sources.xml file.

    Here's my code:
    Code:
    Dim fileSources As IO.File
    If fileSources.Exists(filePath & "sources.xml") Then
      Try
        Dim Sources As XDocument = XDocument.Load(filePath & "sources.xml")
        lblSourcesStatus1.Text = "Sources file found and loaded!"
        lblSourcesStatus2.Text = "path: " & filePath & "sources.xml"
    
        For Each source As XElement In Sources...<sources>.<comicbooks>.<source>
          lbSources.Items.Add(source.<path>.Value)
          Label2.Text = source.<path>.Value
        Next
    
      Catch ex As Exception
        lblSourcesStatus1.Text = "Sources file found, but could not be loaded!"
        lblSourcesStatus2.Text = "path: " & filePath & "sources.xml"
      End Try
    Else
      lblSourcesStatus1.Text = "No sources file found!"
      lblSourcesStatus2.Text = "expected path: " & filePath & "sources.xml"
    End If
    lbSources doesn't get populated with anything and Label2 doesn't change either.

    Please help.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jan 2010
    Location
    San Marcos, TX
    Posts
    177

    Re: get values from xml elements

    Disregard, my XML file had something before the "<?xml version="1.0" encoding="utf-8" ?>" tag, the file wasn't being recognized or loaded.

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