XML data dictionary

I'd like to use xml as a data schema for a vb.net app, but not sure how to get started --- need to get good examples on how to access xml using as vb.net dictionary.
sl1ngerAsked:
Who is Participating?
 
abelConnect With a Mentor Commented:
Put the attached code inside any ASP.NET page, will work with either VB or C#. In the follow-up I'll show how to do it for a windows forms application in VB.


<!DOCTYPE html PUBLIC 
    "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Test XML</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:XmlDataSource runat="server" 
            DataFile="~/EE/Q_24151268.xml"             
            ID="xmlSource" 
            XPath="/dictionary/words/word"
        />
        <asp:Repeater runat="server"
            DataSourceID="xmlSource" >
            <ItemTemplate>
                <p>
                    <b><%#XPath("@lemma")%></b>
                    <br />
                    <%#XPath("text()")%>
                </p>
            </ItemTemplate>
            
        </asp:Repeater>
    </div>
    </form>
</body>
</html>

Open in new window

0
 
Tony McCreathTechnical SEO ConsultantCommented:
I don't quite understand the request.

Do you want a dictionary that you can save/load as xml?
0
 
abelCommented:
A VB.NET Dictionary is known by many as a Hash table or a name/value table. What do you mean by "accessing" XML through such a dictionary? Do you want to store the XML objects inside the dictionary and retrieve them hence? Or the other way around: you want the name/value pairs inside XML and go from there? Can you elaborate a bit on your question? What is your goal?
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 
sl1ngerAuthor Commented:
How do l attach dictionary words to XML and look it up with VB.net?
0
 
abelCommented:
Sorry, that won't really help. Let me try to fill in the blanks for you, maybe this is what you are after?

<words lang="en">
   <word lemma="ligament">
       A ligament is a strong tissue in a person's body which connects bones
   </word>
   <word lemma="lisp">
        If someone has a lisp they pronounce the sounds S and Z as if they were TH. For example, they say "thing" instead of "sing".
   </word>
   ....
</words>
   
And if yes, is your question then actually how to get the words in there? How to create the XML? How to define it? Do you want a DTD/XSD? And/Or how to process it once created through VB?
0
 
sl1ngerAuthor Commented:
Yes.  How would I pull from this in a vb page?
0
 
abelConnect With a Mentor Commented:
Here's the code for use in a VB form. In the screenshot you see the result. In the next message I'll put the XML that I eventually used.

The code you can put under a button, or wherever you like it. Place a TextBox on your form and name it TextBox1. Add a directory Data to your solution and put the XML (of the next comment) in it and call it Q_24151268.xml. Make sure to select "Copy Always" to make debugging and relative paths easier.

Dim xmlDoc As New XmlDocument()
xmlDoc.Load("Data/Q_24151268.xml")
Dim nodes As XmlNodeList = xmlDoc.SelectNodes("/dictionary/words/word")
 
For Each node As XmlNode In nodes
    TextBox1.Text &= node.Attributes("lemma").Value & vbCrLf
    TextBox1.Text &= node.FirstChild.Value.Trim() & vbCrLf & vbCrLf
Next

Open in new window

0
 
abelConnect With a Mentor Commented:
The xml I used.

<?xml version="1.0" encoding="utf-8" ?>
<dictionary>
    <meta>
        Meta info about dict goes here
    </meta>
    
    <words lang="en">
        <word lemma="ligament">
            A ligament is a strong tissue in a person's body which connects bones
        </word>
        <word lemma="lisp">
            If someone has a lisp they pronounce the sounds S and Z as if they were TH. For example, they say "thing" instead of "sing".
        </word>
    </words>
</dictionary>

Open in new window

0
 
abelCommented:
And finally, the result as it shows on a form, in the attached screenshot:

ScreenShot062.png
0
 
abelCommented:
no objections here. I appreciate your work on this, angelIII, wished the askers tended back to their questions occasionally...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.