且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

xml数据到c#.net中的对象?

更新时间:2023-11-02 12:26:04

这是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.