Visual Basic 2008 working with XML

I have the below XML in a field in SQL 2005 and I use Visual Basic 2008 as the front end.  I would like to turn the contents of the SQL field into the text:  Dose:2 unit(s)  Frequency: As needed  Route:Nasal  Last Taken:This morning  

    <Dose>2 unit(s)</Dose>
    <Frequency>As needed</Frequency>
    <LastTaken>This morning</LastTaken>
    <Comments />

Any examples or recommendations on path to take?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Umar Topia.Net Full Stack DeveloperCommented:
In FrontEnd, you can load the XML into XMlDocument and then parse the XML to add the values to the string
dastaubAuthor Commented:
can you demo the mechanics of code for that?
käµfm³d 👽Commented:
Is the field in the database of type xml or type varchar?
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Pratima PharandeCommented:
I think you need this
Sample Code

Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode

'Create the XML Document
m_xmld = New XmlDocument()

'Load the Xml file

'Show all data in your xml

'Get the list of name nodes 
m_nodelist = m_xmld.SelectNodes("/family/name")

'Loop through the nodes
For Each m_node In m_nodelist
'Get the Gender Attribute Value
Dim genderAttribute = m_node.Attributes.GetNamedItem("gender").Value

'Get the firstName Element Value
Dim firstNameValue = m_node.ChildNodes.Item(0).InnerText

'Get the lastName Element Value
Dim lastNameValue = m_node.ChildNodes.Item(1).InnerText

'Write Result to the Console
Console.Write("Gender: " & genderAttribute _
& " FirstName: " & firstNameValue & " LastName: " _
& lastNameValue)

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dastaubAuthor Commented:
Is the field in the database of type xml or type varchar?  = xml
käµfm³d 👽Commented:
This is untested, but you should be able to do something like this:

string newText = string.Empty;

using (System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection(conn_string))
    using (System.Data.SqlClient.SqlCommand cmd =
        new System.Data.SqlClient.SqlCommand("SELECT xmlColumn FROM tableName WHERE recordKey = @keyValue", con))
        cmd.Parameters.Add(new System.Data.SqlClient.SqlParameter("@keyValue", "someKey"));

            System.Xml.XmlReader reader = cmd.ExecuteXmlReader();

            newText += reader.ReadContentAsString() + " ";

            newText += reader.ReadContentAsString() + " ";

            newText += reader.ReadContentAsString() + " ";

            newText += reader.ReadContentAsString();
        catch (System.Data.SqlClient.SqlException ex)

Open in new window

This is dependent on the XML elements being listed in the order that you have displayed them above. If any nodes arrive out of order, then you will be missing data for one or more elements. This would only happen if your schema allowed arbitrary ordering of those elements, or if you are not using a schema, if your writer wrote the elements in an arbitrary order. Typical XML maintains the same ordering on its elements.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.