xml数据到c#.net中的对象? [英] xml data to object in c#.net ?

查看:81
本文介绍了xml数据到c#.net中的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[XmlElement(DataType = typeof(string)),
XmlElement(DataType = typeof(int))]
公共对象[] StringsAndInts;


当我在C#.net中使用XmlElement将xmldata转换为对象时,此代码不起作用?

您能否建议我,如何使用XmlElement(不带XmlElementAttribute)转换xml数据.

解决方案

这是VB代码.也许您需要告诉我们您如何使用C#编写代码?你想做什么 ?我看到一个XmlElement作为成员.我不知道XmlElement可以是通用类型,尽管它很有意义并且很酷.您到底想做什么?如果数据不是int,这会抛出异常吗?我会坚持使用基本XmlElement并使用int.TryParse来查看其中的数据是否为int.


有问题的节点的InnerXml属性将为您提供该功能.

您不应继续发布自己的答案.

您可以使用Google XmlElement或XmlDocument查找所需的任何文档. XPath是用于在DOM文档中查找节点的工具.您确实应该买一本有关XML的书并阅读,这就是为什么我不参考任何种类的书或文章就了解所有这些内容.


[XmlElement(DataType = typeof(string)),
XmlElement(DataType = typeof(int))]
public object[] StringsAndInts;


This code is not working when i converting xmldata to object using XmlElement in c#.net ?

Could you pls advise me, How can I convert xml data using XmlElement(without XmlElementAttribute).

解决方案

This is VB code. Perhaps you need to tell us how you wrote it in C# ? What are you trying to do ? I see an XmlElement as a member. I had no idea XmlElement could be a generic type, although it makes sense and is kind of cool. What are you trying to do exactly ? Will this throw an exception if the data is not an int ? I would stick with the base XmlElement and use int.TryParse to see if the data inside it is an int.


The InnerXml property of the node in question will give you that.


You should not keep posting answers to yourself.

You can google XmlElement, or XmlDocument, to find any documentation you need. XPath is what you use to find nodes in a DOM document. You should perhaps buy a book on XML and read it, I did, and that''s why I know all of this without reference to any sort of book or article.


这篇关于xml数据到c#.net中的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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