Query secondary xml datasource - InfoPath Dev
in

InfoPath Dev

Query secondary xml datasource

Last post 03-07-2006 09:48 AM by sjc724. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 03-06-2006 09:13 AM

    Query secondary xml datasource

    Hi, I'm new to xpath and having a problem creating the query I need.

    I have an xml document as a secondary datasource. I would like to use a text string that the user types in a text box to search for all matching nodes in the xml datasource. I have tried the 'contains' and 'starts-with' xpath functions but neither one seems to work if you pass the search string argument as a string variable.

    Is there a better way to achieve the same results? Is there another xpath function I should be using?

    Thanks.
  • 03-07-2006 04:01 AM In reply to

    Re: Query secondary xml datasource

    Here is a bit more detail:

    I get the text that the user typed and put it in a string variable:

    string searchString = thisXDocument.DOM.selectSingleNode("//SIUData/ReportContacts/last_name").text;

    Then I pass the string variable to an xpath function to find all nodes containing that string:

    contactNodes = thisXDocument.GetDOM("Contacts").selectNodes("ContactData/Contact[contains(last_name, searchString)]");

    And then I get the node count:
    nodeCount = contactNodes.length;

    If I substitute a literal string for the searchString variable, everything works fine. Is there any way I can use a string variable to search an xml document using xpath an query??


  • 03-07-2006 09:48 AM In reply to

    Re: Query secondary xml datasource

    Found the answer, and it is very basic (I lost sight of the fact that the whole 'selectNodes' is taking a string):

    Instead of:

    contactNodes = thisXDocument.GetDOM("Contacts").selectNodes("ContactData/Contact[contains(last_name, searchString)]");

    I needed to do the following:

    contactNodes = thisXDocument.GetDOM("Contacts").selectNodes("ContactData/Contact[contains(last_name,'" + searchString + "')]");
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.