111,126
社区成员
发帖
与我相关
我的任务
分享
SqlConnection str = new SqlConnection("server=.;database=db_test;Trusted_Connection=true");
string str1 = "select 雇员ID,姓氏,头衔 from student";
str.Open();
DataSet dt = new DataSet();
SqlDataAdapter da1 = new SqlDataAdapter(str1, str);
da1.Fill(dt);
dt.WriteXmlSchema("C:\\ttt.xml");
//dt.WriteXml("C:\\tt.xml");
Console.Write("OK!");
str.Close();
<?xml version="1.0" standalone="yes"?>
<xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element name="雇员ID" type="xs:short" minOccurs="0" />
<xs:element name="姓氏" type="xs:string" minOccurs="0" />
<xs:element name="头衔" type="xs:string" minOccurs="0" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
using System.Xml;
//...
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("C:\\ttt.xml");
XmlNamespaceManager nsManager = new XmlNamespaceManager(xmlDoc.NameTable);
nsManager.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
XmlNodeList xmlNodeList = xmlDoc.DocumentElement.SelectNodes(@"//xs:sequence/xs:element", nsManager);
Console.WriteLine("{0} nods founded",xmlNodeList.Count);
foreach (XmlNode node in xmlNodeList)
{
Console.WriteLine("Name={0} Type={1}", node.Attributes["name"].Value, node.Attributes["type"].Value);
}