Hello, I hope I'm in the right place, but I was just wondering what is wrong with this code, as it only finds the parses and saves one word, so I figure something in the for section is incorrect.
It will go through the for section, go through the if statements, which I have the 'greeting' component as being found as true. However, it only saves the first word it finds with the tag 'greeting'. The same applies when parsing other tags such as 'food' (I've removed most below because I don't believe I need to have it all there). Thanks for any help in advance,
and yes, I am a beginner
Edit: to clarify, everything seems to be working fine except that when going through the for section of the code, it only saves one word, instead of about 30 words which have the tag 'greeting'.
And m_node.ChildNodes.Item(4) is the node that contains the tag. Childnodes0 and 1 contain the text that I want to retrieve and save.
It will go through the for section, go through the if statements, which I have the 'greeting' component as being found as true. However, it only saves the first word it finds with the tag 'greeting'. The same applies when parsing other tags such as 'food' (I've removed most below because I don't believe I need to have it all there). Thanks for any help in advance,
and yes, I am a beginner
Edit: to clarify, everything seems to be working fine except that when going through the for section of the code, it only saves one word, instead of about 30 words which have the tag 'greeting'.
And m_node.ChildNodes.Item(4) is the node that contains the tag. Childnodes0 and 1 contain the text that I want to retrieve and save.
VB.NET:
Sub ParseGetPositiveTags()
Try
ListLength = 0
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
m_xmld.Load("C:\Users\Sam\Dictionary.xml")
'Get the list of nodes
m_nodelist = m_xmld.SelectNodes("/Dictionary/Word")
'Loop through the nodes
Dim p As Integer
p = 1
For Each m_node In m_nodelist
If m_node.ChildNodes.Item(4).InnerText = "Greeting" And ListOption.Greetings = True Then
SWordList(p) = m_node.ChildNodes.Item(0).InnerText
EWordList(p) = m_node.ChildNodes.Item(1).InnerText
p = p + 1
ListLength = ListLength + 1
End If
If m_node.ChildNodes.Item(4).InnerText = "Food" And ListOption.Food = True Then
SWordList(p) = m_node.ChildNodes.Item(0).InnerText
EWordList(p) = m_node.ChildNodes.Item(1).InnerText
p = p + 1
ListLength = ListLength + 1
End If
Next
Catch errorVariable As Exception
'Error trapping
MsgBox(errorVariable.ToString())
End Try
End Sub
Last edited: