以动态方式使用XSD读取XML [英] Reading XML with XSD in dynamic way

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

问题描述

大家好,

 我需要一些指导,以动态方式用xsd读取xml betterway。

 I need some guidance to read xml betterway with xsd in dynamic way.

我分析得最好做法 读取和写入xml并找到XMLValidatingReader,因为我的xsd标准是好的。我需要一些指导来设计xsd并以快速和更好的方式读取xml。

I analysed best practices  for reading and writing xml and find XMLValidatingReader as good one beacuse of my xsd criteria. I need some guidance to design xsd and read the xml in fast and better way.

从其他带有数据的ERP系统生成的xml。我需要根据xsd读取xml(从目录)并处理到数据库。

xml generated from other ERP systems with data. I need to read the xml (from directory ) based on the xsd and process to the database.

我有一个xml包的业务实体,包括

I have one business entity for the xml packet which includes

ID,Field1,Field2 Field3等

ID, Field1, Field2 Field3 etc

我需要在读取xml时绑定此实体,以便我将此业务对象分别传递给我的业务方法和DAL。

I need to bind this entity when reading xml so that i pass this business object to my business method and DAL respectively.

1。我如何以更好的方式设计xsd?

1. How i design the xsd in better way?

2。我编写的代码如下

2. I wrote the code as follows


while (reader.Read())
            {
                switch (reader.NodeType)
                {

                    case XmlNodeType.Element:
                        if (reader.Name == "CARRNAME")
                        {
                            label1.Text += reader.Name + "  =  ";
                            reader.Read();
                            if (reader.HasValue)
                            {

                                label1.Text += reader.Value + Environment.NewLine;
                            }
                        }
                        break;
                }
            }

推荐答案

自.NET 2.0以来,XmlValidatingReader已经过时了( http://msdn.microsoft .com / zh-CN / library / system.xml.xmlvalidatingreader%28v = VS.80%29.aspx
所以这些天您应该遵循
http://msdn.microsoft.com/en-us/library/9d83k261.aspx

但是,如果要将基于模式的XML映射到.NET类,还应检查是否使用
XML序列化/反序列化可以为你完成工作,同时还有
xsd.exe命令行工具您可以从您的方案生成.NET类然后让XmlSerializer将XML反序列化为这些类的实例,并将实例
序列化为XML。

However if you want to map schema based XML to .NET classes you should also check whether using XML serialization/deserialization can do the job for you, together with the xsd.exe command line tool you can generate .NET classes from your schema and then let XmlSerializer deserialize XML into instances of these classes and serialize instances to XML.


这篇关于以动态方式使用XSD读取XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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