Pull xPath data with multiple filters applied - InfoPath Dev
in

InfoPath Dev

Pull xPath data with multiple filters applied

Last post 03-10-2011 08:45 AM by wbeard52. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-09-2011 10:13 AM

    Pull xPath data with multiple filters applied

    I am using Visual Basic.net to pull a specific value based out of a secondary datasource.

    I need the @QAnswer node returned with the @TestID and @QNumber nodes filtered

     

    This is what I have so far:

    Dim xPath as string, QA as string

    xpath = "/dfs:myFields/dfs:dataFields/d:Tests/d:TestQuestions/@QAnswer[../@QNumber = '25' AND ../@TestID = 'Test1']"

    QA = DataSources("Tests").CreateNavigator().SelectSingleNode(xpath, NamespaceManager).ToString

     

    I get a general xPath exception was unhandled by user code error.

    Filed under:
  • 03-10-2011 08:18 AM In reply to

    Re: Pull xPath data with multiple filters applied

    What happens if you put your "AND" in lower case? Also, I don't know if VB cares about case, but you declare "xPath" as a variable, then set it using "xpath" and use it as "xpath", both with the "p" lower case....?

    Hilary Stoupa

  • 03-10-2011 08:45 AM In reply to

    Re: Pull xPath data with multiple filters applied

    Thanks Hilary. I tried an uppercase AND and lower case and with no luck.  I finally managed to get the data out and place into a string.  Since each element is only a single character in length I can parse the string as needed to get the data into the correct place.

    'place test answers into a string called QA
    xpath = "/dfs:myFields/dfs:dataFields/d:Tests" 'd:TestQuestions/@QAnswer[../@QNumber = '" & rows.ToString & "']"
    xQAF = DataSources("Tests").CreateNavigator().Select(xpath, NamespaceManager)

    While xQAF.MoveNext
     If xQAF.Current.CreateNavigator().SelectSingleNode("@TestID").ToString = sTestID Then
        xQAA = xQAF.Current.SelectChildren(XPathNodeType.Element)
        strQA =
    " "

        While xQAA.MoveNext
            strQA = strQA & xQAA.Current.CreateNavigator().SelectSingleNode(
    "@QAnswer", NamespaceManager).ToString
       
    End While
        Exit While    'exits the first while statement

     End If
    E
    nd While

    'commented out but if it wasn't will place the correct answer in the dropdown list for the last question
    QA = strQA.Substring(CInt(rows.ToString), 1)

Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.