读取xml模式 [英] reading an xml schema

查看:67
本文介绍了读取xml模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,
我已经在XML文件中放置了一个xml模式
它被放置为第一个Node的后代之一,此xml文件代表一个表

hello,
ive got an xml schema wich is placed inside of an xml file
it is placed as one of the descendants of the first Node , this xml file represnt a table

<newdataset>
   <xs:schema .....="" xmlns:xs="#unknown">
         .
          <xs:element name="Table">
          <xs:complextype>
              <xs:sequence>
                <xs:element name="OrderID" type="xs:int" minoccurs="0" />
                <xs:element name="ProductID" type="xs:int" minoccurs="0" />
                <xs:element name="UnitPrice" type="xs:decimal" minoccurs="0" />
                <xs:element name="Quantity" type="xs:short" minoccurs="0" />
                <xs:element name="Discount" type="xs:float" minoccurs="0" />
              </xs:sequence>
            </xs:complextype>
          </xs:element>
          .
          .
   </xs:schema>
   <record>
        // FIELD NODES
   </record>
   <record>
       // FIELD NODES
   </record>
   .
   .
       // MORE RECORDS 
<newdataset>
</newdataset></newdataset>


我需要检索字段的名称和类型才能创建表示记录的Entity,但是我无法使用内置的ADO.NET函数从此文件中创建数据集.
我可以使用xmlDocument并遍历该模式,直到找到具有name ="table"属性的节点.
我正在寻找一种简单的更好看的方法来完成上述操作.
Linq to xml可能是最合适的方法,但是
似乎有问题 Descendants("xs:element")带有:"更具体.
在此先感谢.


i need to retrive the the name and the type of the fields in order to create an Entity that would represent a record , i cannot use built in ADO.NET function to create a dataset from this file.
i could use xmlDocument and traverse threw the schema untill finding the node with the name="table" , attribute .
im looking for a simple better looking way to do the above .
Linq to xml would of been the most appropriate way but it seems to have a problem with
Descendants("xs:element") with the ":" to be more specific .
thanks in advance .

推荐答案

你好亲爱的
如果要从中加载架构的文件完全为true,则可以执行此操作以将架构从文件加载到DataSet:
Hello Dear
if file which you want load schema from it, is completely true , you can do this to load schema from a file to DataSet :
DataSet Dset = new DataSet();
Dset.ReadXml("FilePath");




or

DataSet Dset = new DataSet();
Dset.ReadXmlSchema("FilePath");


DataSet的ReadXml("FileName")方法从XML文件加载架构和数据
DataSet的ReadXmlSchema("FileName")方法仅从XML文件加载架构.

如果要将模式和数据写入XML文件,可以执行以下操作:


ReadXml("FileName") method of DataSet loads Schema and Data from XML file
ReadXmlSchema("FileName") method of DataSet loads just Schema from XML file

if you want to write schema and data to a XML file you can do these :

Dset.WriteXml("FilePath");
Dset.WriteXmlSchema("FilePath");


这篇关于读取xml模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆