I have googled for the last hour or so with no luck (I'd like to think I'm a great googler too!), so here I am.
I have an XML file that I'm using for my programs settings, it looks like so:
<?xml version="1.0" encoding="utf-8"?>
<config>
<store>
<number>0323</number>
<address>address</address>
<phone>phone</phone>
</store>
<emailsettings>
<emailfrom>emailfrom</emailfrom>
<emailpass>pass</emailpass>
<emailsubject>received</emailsubject>
<smtpserver>smtp.gmail.com</smtpserver>
<smtpport>587</smtpport>
<enablessl>true</enablessl>
<emailbody>package received</emailbody>
</emailsettings>
<dbconfig>
<dbpath>path</dbpath>
</dbconfig>
</config>
How can I use vb.net to get each element and return a specific value that I want? Per se, I'd like to return <number>
(under <store>
) in textbox1, and <emailbody>
(under <emailsettings>
) in textbox2.
Help pleaseeeeee! Thanks :)
Loads the XML document from the specified TextReader. Loads the XML document from the specified XmlReader. Loads the XML document from the specified string. Adds the specified node to the beginning of the list of child nodes for this node.
View an XML file in a browser If all you need to do is view the data in an XML file, you're in luck. Just about every browser can open an XML file. In Chrome, just open a new tab and drag the XML file over. Alternatively, right click on the XML file and hover over "Open with" then click "Chrome".
On the File menu, point to New, and click File. Select XML File in the Templates pane and click Open. A new file is opened in the editor.
XML stands for Extensible Markup Language. It is a text-based markup language derived from Standard Generalized Markup Language (SGML). XML tags identify the data and are used to store and organize the data, rather than specifying how to display it like HTML tags, which are used to display the data.
Ah, a perfect example for showing off the powerful XML features of VB.NET with Framework 3.5:
Sub Main()
Dim xml = XDocument.Load("config.xml")
Console.WriteLine("Number: " & xml.<config>.<store>.<number>.Value)
Console.WriteLine("Body: " & xml.<config>.<emailsettings>.<emailbody>.Value)
End Sub
yields:
Number: 0323
Body: package received
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With