?
Solved

XML data dictionary

Posted on 2009-02-17
11
Medium Priority
?
1,465 Views
Last Modified: 2013-11-10
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.
0
Comment
Question by:sl1nger
  • 7
  • 2
10 Comments
 
LVL 23

Expert Comment

by:Tony McCreath
ID: 23668895
I don't quite understand the request.

Do you want a dictionary that you can save/load as xml?
0
 
LVL 39

Expert Comment

by:abel
ID: 23669155
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
 

Author Comment

by:sl1nger
ID: 23672316
How do l attach dictionary words to XML and look it up with VB.net?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 39

Expert Comment

by:abel
ID: 23673174
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
 

Author Comment

by:sl1nger
ID: 23675458
Yes.  How would I pull from this in a vb page?
0
 
LVL 39

Accepted Solution

by:
abel earned 2016 total points
ID: 23679355
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
 
LVL 39

Assisted Solution

by:abel
abel earned 2016 total points
ID: 23679475
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
 
LVL 39

Assisted Solution

by:abel
abel earned 2016 total points
ID: 23679484
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
 
LVL 39

Expert Comment

by:abel
ID: 23679516
And finally, the result as it shows on a form, in the attached screenshot:

ScreenShot062.png
0
 
LVL 39

Expert Comment

by:abel
ID: 24010924
no objections here. I appreciate your work on this, angelIII, wished the askers tended back to their questions occasionally...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
Integration Management Part 2
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question