I have a textbox that people would need to use to search a xml file. If a record is found with that worrd as keyword then the item is returned. I need to return ID, for example, but I dont seem to find the way to do this. Could you help? Thanks. This is what I have but I get "Object reference not set to an instance of an object."
Expand|Select|Wrap|Line Numbers
- Dim d() As String
- Dim j As Integer
- d = TextBox1.Text.Split(" ")
- Dim xpathexpression As String = ""
- For j = 0 To d.GetUpperBound(0)
- xpathexpression = xpathexpression & "contains(CONTRACTKEYWORDS,'" & d(j) & "')"
- If j < d.GetUpperBound(0) Then
- xpathexpression = xpathexpression & " or "
- End If
- Next
- Dim xdoc As New XPathDocument(AppDomain.CurrentDomain.BaseDirectory + "/testxml.xml")
- Dim nav As XPathNavigator = xdoc.CreateNavigator()
- Dim nodes As XPathNodeIterator = nav.Select("/CONTRACTS/CONTRACT/*[" & xpathexpression & "]")
- tr += "<tr><td>" & nav.SelectSingleNode("ID").Value & "</td>"
- For Each node As XPathNavigator In nodes
- tr += "<td>" & node.SelectSingleNode("CONTRACTKEYWORDS").Value & "</td></tr>"
- Next
- Dim th As String = "<th>Commodity</th><th>Name</th><th>Supplier</th><th>Name</th>"
- div1.InnerHtml = ("<table class='datatable1'>" & th) + tr & "</table>"
Expand|Select|Wrap|Line Numbers
- <CONTRACTS>
- <CONTRACT>
- <ID>779</ID>
- <NAME>ContractName779</NAME>
- <STARTDATE>1/8/2005</STARTDATE>
- <ENDDATE>31/7/2008</ENDDATE>
- <COMMODITIES>
- <COMMODITY>
- <COMMODITYCODE>CHEM</COMMODITYCODE>
- <COMMODITYNAME>Chemicals</COMMODITYNAME>
- </COMMODITY>
- </COMMODITIES>
- <SUPPLIERS>
- <SUPPLIER>
- <SUPPLIERID>1298</SUPPLIERID>
- <SUPPLIERNAME>Supplier name</SUPPLIERNAME>
- </SUPPLIER>
- </SUPPLIERS>
- <CONTRACTTERMS>
- <CONTRACTKEYWORDS>Chemistry, Engineering, Chemical</CONTRACTKEYWORDS>
- </CONTRACTTERMS>
- </CONTRACT>
- </CONTRACTS>