search dataset from xml file

Posted by Anelim on Stack Overflow See other posts from Stack Overflow or by Anelim
Published on 2010-02-24T16:45:06Z Indexed on 2010/04/15 23:03 UTC
Read the original article Hit count: 455

Filed under:
|
|

Hi, I need to filter the results I obtain when I load my xml file. For example I need to search the xml data for items with keyword "Chemistry" for example. The below xml example is a summary of my xml file. The data is loaded in a gridview. Could you help? Thanks!

Xml File (summary):

<CONTRACTS> <CONTRACT> <CONTRACTID>779</CONTRACTID> <NAME>ContractName</NAME> <KEYWORDS>Chemistry, Engineering, Chemical</KEYWORDS> <CONTRACTSTARTDATE>1/8/2005</CONTRACTSTARTDATE> <CONTRACTENDDATE>31/7/2008</CONTRACTENDDATE> <COMMODITIES><COMMODITY><COMMODITYCODE>CHEM</COMMODITYCODE> <COMMODITYNAME>Chemicals</COMMODITYNAME></COMMODITY></COMMODITIES> </CONTRACT></CONTRACTS>

My code behind code is:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim ds As DataSet = New DataSet()

    ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory + "/testxml.xml")

    Dim dtContract As DataTable = ds.Tables(0)
    Dim dtJoinCommodities As DataTable = ds.Tables(1)
    Dim dtCommodity As DataTable = ds.Tables(2)
    dtContract.Columns.Add("COMMODITYCODE")
    dtContract.Columns.Add("COMMODITYNAME")

    Dim count As Integer = 0
    Dim commodityCode As String = Nothing
    Dim commodityName As String = Nothing

    Dim dRowJoinCommodity As DataRow
    Dim trimChar As Char() = {","c, " "c}

    Dim textboxstring As String = "KEYWORDS like 'pencil'"

        For Each dRow As DataRow In dtContract.Select(textboxstring)

        commodityCode = ""
        commodityName = ""

        count = dtContract.Rows.IndexOf(dRow)
        dRowJoinCommodity = dtJoinCommodities.Rows(count)

        For Each dRowCommodities As DataRow In dtCommodity.Rows
            If dRowCommodities("COMMODITIES_Id").ToString() = dRowJoinCommodity("COMMODITIES_ID").ToString() Then

                commodityCode = commodityCode + dRowCommodities("COMMODITYCODE").ToString() + ", "

                commodityName = commodityName + dRowCommodities("COMMODITYNAME").ToString() + ", "

            End If

        Next

       commodityCode = commodityCode.TrimEnd(trimChar)
        commodityName = commodityName.TrimEnd(trimChar)
        dRow("COMMODITYCODE") = commodityCode
        dRow("COMMODITYNAME") = commodityName

    Next


    GridView1.DataSource = dtContract
    GridView1.DataBind()
End Sub

© Stack Overflow or respective owner

Related posts about Xml

Related posts about dataset