Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Load XML Attributes and put Values in VB.NET Controls

Status
Not open for further replies.

matthewtbaker

Technical User
Dec 1, 2011
2
GB
Hi,

I've been searching high a low for a clear solution but cannot find one, so hope you can help me understand what I should do.

I have an xml file called mymovie.xml (below) which I want to load and pick out certain attributes. I then want to output the values into named labels (lblLocalTitle, lblProductionYear etc.) when btnInfo is clicked.

Any help on how to load and pick out the required values will be very much appreciated!

Best Regards
Matthew T. Baker



<?xml version="1.0"?>
<Title>
<LocalTitle>Anchorman</LocalTitle>
<ProductionYear>2004</ProductionYear>
<RunningTime>94</RunningTime>
<Type>Blu-ray</Type>
</Title>
 
For those looking for the answer, I've discovered it.

Dim strFile As String = "mymovie.xml"
Dim xmlDoc As XDocument = XDocument.Load(strFile)

For Each Title As XElement In xmlDoc.Descendants("Title")
If Title.HasElements = True Then
lblLocalTitle.Text = (Title.Element("LocalTitle").Value)
lblDescription.Text = (Title.Element("Description").Value)
End If
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top