EDN Admin
Well-known member
I have a Procedure that is supposed to get the value of an attribute in an xml file. The first 4 times I call the Procedure, it works fine. But on the 5th time the value of myNode is Nothing.
I dont think the problem is with the xml file because if change the order of the nodes, I still get the same problem - always on the 5th call of the Procedure.
Procedure:
<pre class="prettyprint lang-vb Sub SaveMyResponse(ByVal CurrentQuestion As Integer)
Dim QuestionResponseValue As Integer
Dim i As Integer
Dim xmlDoc As New Xml.XmlDocument
xmlDoc.LoadXml(My.Resources.census_questions)
Dim myNode As XmlNode
myNode = xmlDoc.GetElementsByTagName("responses").Item(CurrentQuestion)
Loop through responses to get the numeric value for the response
For i = 0 To myNode.ChildNodes.Count - 1
get the value of the response
If MyComboButton.Text = myNode.ChildNodes(i).InnerText Then
surveyResponseValue = myNode.ChildNodes(i).Attributes("value").Value
Exit For
End If
Next i
End Sub[/code]
portion of the xml:
<pre class="prettyprint <question type=dropdown fieldname=marital qnumber=5>
<text>5. What is your marital status?</text>
<responses>
<response value=1>Single</response>
<response value=2>Married</response>
<response value=3>Widowed</response>
<response value=4>Divorced</response>
<response value=5>Separated</response>
</responses>
</question>[/code]
<br/>
<br/>
View the full article
I dont think the problem is with the xml file because if change the order of the nodes, I still get the same problem - always on the 5th call of the Procedure.
Procedure:
<pre class="prettyprint lang-vb Sub SaveMyResponse(ByVal CurrentQuestion As Integer)
Dim QuestionResponseValue As Integer
Dim i As Integer
Dim xmlDoc As New Xml.XmlDocument
xmlDoc.LoadXml(My.Resources.census_questions)
Dim myNode As XmlNode
myNode = xmlDoc.GetElementsByTagName("responses").Item(CurrentQuestion)
Loop through responses to get the numeric value for the response
For i = 0 To myNode.ChildNodes.Count - 1
get the value of the response
If MyComboButton.Text = myNode.ChildNodes(i).InnerText Then
surveyResponseValue = myNode.ChildNodes(i).Attributes("value").Value
Exit For
End If
Next i
End Sub[/code]
portion of the xml:
<pre class="prettyprint <question type=dropdown fieldname=marital qnumber=5>
<text>5. What is your marital status?</text>
<responses>
<response value=1>Single</response>
<response value=2>Married</response>
<response value=3>Widowed</response>
<response value=4>Divorced</response>
<response value=5>Separated</response>
</responses>
</question>[/code]
<br/>
<br/>
View the full article