Results 1 to 8 of 8

Thread: [RESOLVED] More 3.0 to 3.5 issues

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Resolved [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
    Last edited by staticbob; Feb 15th, 2009 at 06:02 PM.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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:
    1. For Each xn As XmlNode in document.SelectNodes("/root/parent/question")
    2. 'do an xn.SelectSingleNode("SectionName") and get its .value or .innertext
    3. Next

  3. #3

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    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()
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  5. #5

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: More 3.0 to 3.5 issues

    OK, this gets me into the right place.... the matching section from the XML file...



    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 = ""}
    Last edited by staticbob; Feb 17th, 2009 at 06:28 AM.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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.

  7. #7

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    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
    Last edited by staticbob; Feb 18th, 2009 at 05:40 AM.
    "I dislike 7 am. If 7 am were a person, I would punch 7 am in the biscuits." - Paul Ryan, DailyRamblings

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width