简体   繁体   中英

asp.net c# search function in several xml files

I have an several XML files and i want to create an search function, for instance if the user search for "Information System" or just "System" it will find the specific project and display it. There are 20 XML files and i am not allow to change the structure of the XML files. i started to write the search function, but i don't sure how to continue.

buttons aspx code:

<asp:TableCell>
<asp:TextBox runat="server" ID="filterTB"></asp:TextBox>
 <asp:Button ID="btnSearch" runat="server" Text="search" />
</asp:TableCell>

particle example of XML :

<project>
    <name>Shema Information System</name>
    <type>Information System</type>
    <faculty>IE</faculty>
    <year>2013</year>
    <customer>
        <name>Shema association</name>
    </customer>
    <students>
        <groupCode>igroup28</groupCode>
    </students>
</project>

aspx.cs code:

protected void btnSearch_Click(object sender, EventArgs e)
{
    string text = filterTB.Text;

    string[] textArr = text.Split(new char[] { ' ', '\n', ',' });
}

You may proceed with following way:

  1. Loop thru all the xml files by using Direcoty.GetFiles()
  2. Read the "name", "type" etc nodes and compare their value with your textArr
  3. When you find a match, add that file in a list, and show it to users.

Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM