如何使用xml文件并在Html.DropDownList中显示? [英] how use xml file and display in Html.DropDownList?

查看:95
本文介绍了如何使用xml文件并在Html.DropDownList中显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个页面,其中包含名称,活动和位置,用于regester客户,

但位置包含部分城市,保存在XML文件中,现在大多数显示在页面中的XML文件中,但是

我不知道

1-如何从XML文件(仅部分或仅部分城市)读取位置?

2-如何在Html.DropDownList中显示位置?

3-如何将位置与页面客户的其他详细信息相结合?

解决方案

您没有共享位置和其他详细信息的表示方式,所以您自己.
您可以使用以下方法来解析XML:


  1. 使用System.Xml.XmlDocument类.它实现了DOM接口;如果文档太大,则这种方法最简单,也足够好.
    请参见
  2. 使用类System.Xml.XmlTextReader; library/system.xml.xmldocument.aspx"target =" _ blank"title =" New Window> ^ ].
  3. 使用类System.Xml.XmlTextReader;这是最快的读取方法,尤其是您需要跳过一些数据.
    请参见 http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx [ http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx [http://msdn.microsoft.com/en-us/library/bb387063.aspx [ http://msdn.microsoft.com/en-us/library/ms733127.aspx [ ^ ].

    另请参阅我以前的答案,其中我对此方法表示支持:
    如何在我的表单应用程序? [ ^ ],
    创建属性文件... [ 解决方案

You did not share how you represent Location and other detail, so you''re on your own.
You can use the following approached to parse XML:


  1. Use System.Xml.XmlDocument class. It implements DOM interface; this way is the easiest and good enough if the size if the document is not too big.
    See
    http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^].
  2. Use the class System.Xml.XmlTextReader; this is the fastest way of reading, especially is you need to skip some data.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx[^].
  3. Use the class System.Xml.Linq.XDocument; this is the most adequate way similar to that of XmlDocument, supporting LINQ to XML Programming.
    See http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx[^], http://msdn.microsoft.com/en-us/library/bb387063.aspx[^].



Now, do you have to read existing XML with already predefined schema, or you can generate your own? It would be much better. In this case, you should use serialization instead of doing it all on a level of XML.

The best really non-intrusive way to serialize is the Data Contract.

See http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past answers where I argument in favor of this approach:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating a property files...[^].

—SA


这篇关于如何使用xml文件并在Html.DropDownList中显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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