XPath related notes

Source: Internet
Author: User

<?xml version= "1.0" encoding= "Utf-8"?><employees>  <employee on= >    <name>Tom</name>    <sex> men </sex>    <birth>      <year>1982</year>      < month>5</month>      <day>22</day>    </birth>    < sales>      <year>2010</year>      <month>1</month>      <sale>320000</sale>    </sales>    <salary>8600</salary >  </employee>    <employee on= "to" >    <name>Jack</name>     <sex> men </sex>    <birth>      <year>1981</year>       <month>7</month>      <day>10</day>    </ birth>    <sales>      <year>2010</year>      <month>1</month>      <sale>300000</sale>    </sales>    <salary>6000</salary>  </employee>  <employee on= " ">    <name>Jennifer</name>    <sex> women </sex>    <birth >      <year>1982</year>      <month>6</month>    & nbsp <day>22</day>    </birth>    <sales>      <year>2010 </year>      <month>1</month>      <sale>500000</sale>     </sales>    <salary>7000</salary>  </employee>  < /employees>=============================================================using System;using System.collections.generic;using system.linq;using system.web;using system.web.ui;using SysTem. Web.ui.webcontrols;using system.xml.xpath;namespace webapplication{    Public partial class Xpathnav: system.web.ui.page    {        protected void Page_Load (object sender, EventArgs e)   &N Bsp     {       }        protected void Btnnav_click (object sender, Eventar GS e)         {           //Create XPathDocument object             XPathDocument Xdoc = new XPathDocument (Server.MapPath ("~/employees.xml"));       & nbsp    //Create XPath navigation             XPathNavigator xnav = Xdoc. CreateNavigator ();           //Loading iterators (results)             Xpathnode Iterator Iterator = Xnav. Select ("Descendant::employee");              String outPut = ";            while (iTerator. MoveNext ()) {                OutPut + = "Employees:" + iterator. Current.selectsinglenode ("name"). Value+ "<br/>"; Look for a single node under the current node name value                 OutPut + = "+" Salary: "+ iterator. Current.selectsinglenode ("Salary"). Value + "<br/>"; Find the value of single node salary under current node                 OutPut + = "

XPath related notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.