XMLtextreader need a bit of help

liunx

Guest
K guys this is going to haunt me as it probably very easy...

I have XML file like so

<Database>

<CommonWord>

<keyWord>tech</KeyWord>

<Word>technology</Word>

<Word>Technical</Word>

</CommonWord>

and then repeats x amount of times.

</Database>

anyway im trying to get itto read this in to a hashtable but I am just testing t to ensure it comes out tech then word, word etc. and then repeats.

however at moment all I am popping out is the KeyWords and not any of the words. Can anyone tell me how to get the words out one after another for a Keyword.

code so far is this.

try

While xread.Read() ' Start of the xml reading

Select Case xread.NodeType

Case XMLNodeType.Element

if xread.Name = "KeyWord" then

Word = Xread.ReadString()

response.write("Key Word: " & Word & "<br>")

While Xread.EOF()

if Xread.Name = "Word" then

response.write(Xread.ReadString())

end if

End While

'StopWord.Item("stopword" & j) = Word

'Word = ""

'j = j + 1

end if

End Select

End While

Finally

xread.close()

End tryhey guys I have gotten myself confused..

I have got it to feed in the xml to the hash table and I have 2 keys which is correct...however is there away to count the number of values to each key? as when i do a search I am always recieving nothing...I have even tried search to see if it even contains the word in the value but it returns false any help would be great.

CODE

<%@ Page Language="VB" ContentType="text/html" Debug="true" Explicit="True"%>

<%@ Import Namespace="System.XML"%>

<%@ Import Namespace="System.IO"%>

<%@ Import Namespace="System.Data" %>

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>

<body>



<script language="VB" Runat="server">

dim Xread = new XMLTextReader(Server.MapPath("App_Data/XML/CommonWord.xml"))

dim CommonWord = New Hashtable

Dim arrName as new arraylist

Dim saying as String = "Tech"


Sub Page_Load()

dim y

For Each C As Char In saying.ToCharArray

If Char.IsLetterOrDigit(C) Then

y &= C

Else

If y <> "" Then

arrName.Add(y)

y = ""

End If

End If

Next

If y <> "" Then arrName.Add(y)

dim j

try

While xread.Read() ' Start of the xml reading

Select Case xread.NodeType

Case XMLNodeType.Element

if Xread.Name = "KeyWord" then

Word = Xread.ReadString()

response.write("KeyWord: " & Word & "<BR>")

CommonWord.Item(Word)

elseif Xread.Name = "Word"

response.write("Common Word: " & Xread.ReadString() & " of " & Word & "<BR>")

CommonWord.Item(Word) = Xread.ReadString()

end if

End Select

End While

Finally

xread.close()

End try

response.write("<br>-----------------------------<br><u><b>Total Size of Hashtable</b></u><br> <b>Number of Keys =</b>" & CommonWord.Count & "<br>-----------------------------<br>")

CommonWordRemoval()

end sub

sub CommonWordRemoval()

dim CommonTerm as string

dim i, k as integer

dim j as integer = 0

i = arrName.count

Do Until j = i

response.write("<br> Users Word: " & arrName(j) & "<br>")

CommonTerm = CommonWord.Item(arrName(j))

response.write("Has Common Word: " & CommonTerm & "<BR>")

j = j + 1

Loop

end sub

</script>

</body>

</html>


A visual picture of the out put for above code at the moment

KeyWord: Technology
Common Word: Technological of Technology
Common Word: Tech of Technology
Common Word: Technology of Technology
KeyWord: Get
Common Word: Gets of Get
Common Word: Got of Get
Common Word: Gotten of Get

-----------------------------
Total Size of Hashtable
Number of Keys =2
-----------------------------

Users Word: Tech
Has Common Word:



Can you explain why this is happening as I am at a complete loss....I have checked there are keys in the hashtable but not sure about values as I am not sure how to output a hashtable so its viewable.



Thanks again for any help
 
Top