[RESOLVED] More 3.0 to 3.5 issues
Guys,
I have to take a project from 3.5 down to 3.0.
The 3.5 project is making use of the linq.xdocument in the following code, can somebody show how I do this in 3.0 please?
I've replaced the xdocument with xmldocument, but the ".Descendants" is giving me erros now obviously.
Ta
Bob
Code:
'This gets the questions with any completed data.
Dim document As XmlDocument = XmlDocument.Load(Session("str_XMLDataFile"))
Dim sectionName As String = XPathBinder.Eval(DataBinder.GetDataItem(e.AccordionItem), "@SectionName").ToString()
Dim questions = From question In document.Descendants("Question") _
Where question.Parent.Attribute("SectionName").Value = sectionName _
Select Text = question.Element("Text").Value, _
Comment = question.Element("Comment").Value, _
VDSCode = question.Element("VDSCode").Value, _
Category = question.Element("Category").Value, _
YesNo = question.Element("YesNo").Value
Re: More 3.0 to 3.5 issues
You'd have to use proper XPath in this case, and your LINQ query gets replaced by a for-each loop. To get the descendants you'll need the SelectNodes() method of XmlDocument.
vb Code:
For Each xn As XmlNode in document.SelectNodes("/root/parent/question")
'do an xn.SelectSingleNode("SectionName") and get its .value or .innertext
Next
Re: More 3.0 to 3.5 issues
ok, but get the results into what type of object? Previously, I was just binding the repeater to the query results in "questions"...
Code:
Dim lstQuestions As Repeater = TryCast(e.AccordionItem.FindControl("lstQuestions"), Repeater)
lstQuestions.DataSource = questions
lstQuestions.DataBind()
Re: More 3.0 to 3.5 issues
You can create a List<Question>, populate it from your XML, and then bind that to the lstQuestions object.
Re: More 3.0 to 3.5 issues
OK, this gets me into the right place.... the matching section from the XML file...
http://i63.servimg.com/u/f63/12/13/53/25/cabbag11.jpg
But how do I know get the data from the innerXML of "xmlq" into a list, in a format that I can bind to. As I have with the linQ query, like this...
Here is an example of a query result set from the working linQ code...
Code:
(0) = {Text = "Datum, Secondary, Clearance Fixings ", Comment = "123123123123123", VDSCode = "123123", Category = "C", YesNo = "No"}
(1) = {Text = "Assistor required? ", Comment = "", VDSCode = "", Category = "", YesNo = ""}
(2) = {Text = "Protection / Damage potential ", Comment = "", VDSCode = "", Category = "", YesNo = ""}
Re: More 3.0 to 3.5 issues
Right, so first create a class that holds a property for each of those fields. (Text, Comment, VDSCode, Category, YesNo). In your loop, you need to use xmlq.SelectSingleNode() to get those inner nodes out.
xmlq.SelectSingleNode("Text").InnerText
xmlq.SelectSingleNode("VDSCode").InnerText
and so on. You use each of those to populate an instance of the class that you created to hold those properties. As you create each object, add it to the list.
Re: More 3.0 to 3.5 issues
Sorted, thanks...
Code:
For Each xn As XmlNode In document.SelectNodes("/PPRObject/Section")
If xn.Attributes(0).Value = sectionName Then
For Each xmlq As XmlNode In xn.ChildNodes
Dim QA As New QAnswers
QA.Text = xmlq.SelectSingleNode("Text").InnerText
QA.Comment = xmlq.SelectSingleNode("Comment").InnerText
QA.VDSCode = xmlq.SelectSingleNode("VDSCode").InnerText
QA.Category = xmlq.SelectSingleNode("Category").InnerText
QA.YesNo = xmlq.SelectSingleNode("YesNo").InnerText
questions.Add(QA)
Next
Exit For
End If
Next
Re: [RESOLVED] More 3.0 to 3.5 issues
No problem. So... just out of curiosity, why do you need to go from 3.5 to 3.0?