reading xml file

mars

Member
Joined
Jun 19, 2006
Messages
13
Programming Experience
1-3
Hi

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.

regards
Mars
 
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]")
 
Back
Top