i'm newbie here.
i using vb.net language to write a program....
but facing some problem....
My problem is like that:
I wan to read the xml file,then filtering or searching the specific element in xml file based on the criteria.
FOR EXAMPLE: My XML file data is like below
ABC
Sdn Bhd
Process
Manager
Process Manager (Content
Search)
27-Apr-2006
1
XYZ
Sdn
Bhd
Basic
Version
Control (Content Search)
27-Jan-2006
Admin
-->I want to read the data on XML file,but i dun1 show all data out. i just need search a record base on child element.
-->and my system is ask user to choose the month and year in separate drop down list (example: month:Apr
Year:2006),then clicking a command button, the result of output will show out the data based on the date that
user choose. And the record in XML file that did not match the User choose date will not be show out.
--->If user choose month: Apr and Year: 2006, then the ABC Sdn Bhd
record will show out after debugging. The XYZ Sdn Bhd record will not show out after
debugging.
How to make it be possible ya?? Can show me the source code in vb.net programming language?? i create this by using visual studio 2005.
thanks in advanced for those who shared theirs experience or giving me some help...
can provides me some samples? thanks.
i using vb.net language to write a program....
but facing some problem....
My problem is like that:
I wan to read the xml file,then filtering or searching the specific element in xml file based on the criteria.
FOR EXAMPLE: My XML file data is like below
-->I want to read the data on XML file,but i dun1 show all data out. i just need search a record base on child element.
-->and my system is ask user to choose the month and year in separate drop down list (example: month:Apr
Year:2006),then clicking a command button, the result of output will show out the data based on the date that
user choose. And the record in XML file that did not match the User choose date will not be show out.
--->If user choose month: Apr and Year: 2006, then the ABC Sdn Bhd
record will show out after debugging. The XYZ Sdn Bhd record will not show out after
debugging.
How to make it be possible ya?? Can show me the source code in vb.net programming language?? i create this by using visual studio 2005.
thanks in advanced for those who shared theirs experience or giving me some help...
can provides me some samples? thanks.
Tan RinoPosted Jan 20, 2008, 9:46 PM
Thanks your helping.
Thanksss so much...
hope will learn more from you in the coming future.
NainilPosted Jan 19, 2008, 8:56 PM
That is very simple. Let's assume that you have 2 DropDownList controls on the form named dplMonth and dplYear. dplMonth holds items with month names for example Jan, Feb, Mar, etc. dplYear holds items with years for example 1999, 2000, 2001, etc. On the click on the button, you will have to create a string variable (called month_Year) and store dplMonth.Text & "-" & dplYear.Text. Then use the same string variable to query the node. Following is the example code snippet:
xmlDoc.SelectNodes("//date_created [contains(.," & month_Year & ")]")
This should do it.
Tan RinoPosted Jan 16, 2008, 2:52 AM
how to link the date_created [contains(.,'Apr-2007') to ddlMonth and ddlYear ? i dun want just search "Apr-2007" record, i want search the overall record flexibel when choose the month and year.
when user select from drop down list Month and Year,then click generate command button, the searching record based on date(Month and Year) will list out.
Dim
nodes As XmlNodeList = xmlDoc.SelectNodes("//date_created [contains(.,'Apr-2007')]")thanks...
NainilPosted Jan 15, 2008, 2:51 PM
To get the list of nodes with the company_name from your XML, you will have to use the XmlDocument.SelectNodes("//date_created [contains(."Apr-2006')]") sub to query the XmlDocument. This will return a XmlNodeList object which holds all the XmlNode objects that has a value of "Apr-2006". Then you will have to itreate throug the XmlNodeList collection and foreach node, you will have to get the parentnode. Once you have the parentNode, you will then need to get the first ChildNode. This should return you the node "ABC Sdn Bhd".
Here is the code to accomplish the task:
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("../../XMLFile1.xml")
Dim nodes As XmlNodeList = xmlDoc.SelectNodes("//date_created [contains(.,'Apr-2007')]")
If Not (nodes Is Nothing) And nodes.Count > 0 Then
Dim oStringBuilder As New StringBuilder()
Dim oNode As XmlNode
For Each oNode In nodes
oStringBuilder.AppendLine(oNode.ParentNode.ChildNodes(0).InnerText)
Next oNode
MessageBox.Show(oStringBuilder.ToString())
Else
MessageBox.Show("Node either null or 0")
End If
If you would like a working sample, please mail me ([email protected]) and I will forward the sample. Thanks.