日期:2014-05-17  浏览次数:21527 次

c# 读取xsd文件(Schema文件)
C# 如何读取xsd文件?就是Schema文件,此文件内容大概如下:
<?xml version="1.0" encoding="UTF-8"?>

<xs:schema xmlns:snp="http://www.sinopec.com/cas/2010-12-31" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xbrldt="http://xbrl.org/2005/xbrldt" xmlns:nonnum="http://www.xbrl.org/dtr/type/non-numeric" xmlns:num="http://www.xbrl.org/dtr/type/numeric" targetNamespace="http://www.sinopec.com/cas/2010-12-31" elementFormDefault="qualified">
  <xs:annotation>
  <xs:appinfo>
  <link:roleType roleURI="http://www.sinopec.com/role/cas/837200/020504a" id="RT_020504b">
  <link:definition>[020504a] Details - Cash at bank and on hand</link:definition>
  <link:usedOn>link:calculationLink</link:usedOn>
  <link:usedOn>link:definitionLink</link:usedOn>
  <link:usedOn>link:presentationLink</link:usedOn>
  </link:roleType>
  </xs:appinfo>
  </xs:annotation>
  <xs:import namespace="http://www.xbrl.org/2003/instance" schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd"/>
  <xs:import namespace="http://xbrl.mof.gov.cn/taxonomy/2010-09-30/cas" schemaLocation="http://xbrl.mof.gov.cn/taxonomy/2010-09-30/cas_core_2010-09-30.xsd"/>
  <xs:element name="WeightedAverageNumberOfOutstandingOrdinarySharesOfTheCompany" id="snp_WeightedAverageNumberOfOutstandingOrdinarySharesOfTheCompany" type="xbrli:sharesItemType" substitutionGroup="xbrli:item" nillable="true" xbrli:periodType="duration" abstract="false"/>
  <xs:element name="WeightedAverageNumberOfOutstandingOrdinarySharesOfTheCompanyDiluted" id="snp_WeightedAverageNumberOfOutstandingOrdinarySharesOfTheCompanyDiluted" type="xbrli:sharesItemType" substitutionGroup="xbrli:item" nillable="true" xbrli:periodType="duration" abstract="false"/>
  <xs:element name="WeightedAverageNumberOfTheOrdinarySharesIssued" id="snp_WeightedAverageNumberOfTheOrdinarySharesIssued" type="xbrli:sharesItemType" substitutionGroup="xbrli:item" nillable="true" xbrli:periodType="duration" abstract="false"/>
domainItemType" substitutionGroup="xbrli:item" nillable="true" xbrli:periodType="duration" abstract="true"/>
</xs:schema>


------解决方案--------------------
C# code

XmlDocument doc = new XmlDocument();
            doc.Load(""); 
            XmlNodeList nodelist = doc.SelectNodes("xpath");
            foreach (XmlNode item in nodelist)
            {
                //item.InnerText
                //item.Attributes["name"].InnerText
            }

------解决方案--------------------
还可以使用Linq to XML来读取XML
C# code
 XDocument docc = XDocument.Load("uri");

------解决方案--------------------
doc.Load("这里要写上你的文件路径");