I have an xml file and want to read it.
But i want to read it like
"select * from table1 where id = 4"
is there any method i just read a single record from that file on any criteria.
Xml have its own query language called XPath. Several .Net objects/methods support this. It is very different from SQL queries, something that reflects the usage foundation, which for Xml is primary storage space as date source for web presentations and other small data 'tables'.
You can read a XPath tutorial at W3C Schools: http://www.w3schools.com/xpath/default.asp Much info should be available other web places too, often in relation to Xml and Xsl transformations that uses the same XPath queries.
Here is a basic example that loads a Xml document and gets a list of 'item' nodes with the SelectNodes method from the '/root/cat' node where their 'id' attribute is '4'. Also included the SelectSingleNode method with same query that will return the first if several matches.
VB.NET:
Dim xdoc As New Xml.XmlDocument
xdoc.Load(strFilename)
Dim xnl As Xml.XmlNodeList = xdoc.SelectNodes("/root/cat/item[@id=4]")
Dim xn As Xml.XmlNode = xdoc.SelectSingleNode("/root/cat/item[@id=4]")
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.