使用XmlSerializer进行序列化:如何将XML根节点设置为与< ArrayOfClassname> ????不同的东西 [英] Serialization with XmlSerializer: how to set the XML root node to something different from <ArrayOfClassname>????
问题描述
你好,
使用
XmlSerializer.Serialize()序列化类Classname的元素数组时,我得到如下XML:
<?xml version =" 1.0">
< ArrayOfClassname>
...... 。
.......
< / ArrayOfClassname>
我希望能够将XML根节点设置为不同于
< ArrayOfClassname> ....例如< Classnames> ;.
作为一种替代方法,当如下所述对XML进行deserilizing时:
<?xml version =" 1.0">
< Classnames>
.......
.......
< / Classnames>
我希望能够加载它成为类Classname
的对象数组(在进行此类尝试的那一刻,我得到一个明显的例外
陈述"< Classnames>未被预期 )。
Bob Rock
Hello,
when serializing an array of elements of a class Classname using
XmlSerializer.Serialize() I get an XML like the following:
<?xml version="1.0">
<ArrayOfClassname>
.......
.......
</ArrayOfClassname>
I''d like to be able to set the XML root node to something different from
<ArrayOfClassname> .... for example something like <Classnames>.
As an alternative when deserilizing an XML such as the following:
<?xml version="1.0">
<Classnames>
.......
.......
</Classnames>
I''d like to be able to "load" it into an array of objects of class Classname
(at the moment when making such an attempt I get an obvious exception
stating "<Classnames> was not expected").
Bob Rock
推荐答案
XmlArrayAttribute
参见参考:
http://msdn.microsoft .com / library / en ... ClassTopic.asp
和指南:
http://msdn.microsoft.com/library/en...attributes.asp
-Dino
ps:无需交叉发布
" Bob Rock" <无*************************** @ hotmail.com>在留言中写道
新闻:O3 ************* @ tk2msftngp13.phx.gbl ...
XmlArrayAttribute
see reference:
http://msdn.microsoft.com/library/en...ClassTopic.asp
and guide:
http://msdn.microsoft.com/library/en...attributes.asp
-Dino
ps: no need to cross-post
"Bob Rock" <no***************************@hotmail.com> wrote in message
news:O3*************@tk2msftngp13.phx.gbl...
你好,
使用XmlSerializer.Serialize()序列化类Classname的元素数组时,我得到如下的XML:
<?xml version =" 1.0" ;>
< ArrayOfClassname>
......
......
< / ArrayOfClassname>
我'我希望能够将XML根节点设置为与
< ArrayOfClassname>不同的东西。 ....例如类似< Classnames> ;.
作为替代XML时的替代方法,如下所示:
<?xml version =" 1.0">
< Classnames>
......
......
< / Classnames>
我想要能够加载它成为类
Classname的对象数组(在进行此类尝试的那一刻,我得到一个明显的例外
声明< Classnames>未被预期)。
Bob Rock
Hello,
when serializing an array of elements of a class Classname using
XmlSerializer.Serialize() I get an XML like the following:
<?xml version="1.0">
<ArrayOfClassname>
......
......
</ArrayOfClassname>
I''d like to be able to set the XML root node to something different from
<ArrayOfClassname> .... for example something like <Classnames>.
As an alternative when deserilizing an XML such as the following:
<?xml version="1.0">
<Classnames>
......
......
</Classnames>
I''d like to be able to "load" it into an array of objects of class Classname (at the moment when making such an attempt I get an obvious exception
stating "<Classnames> was not expected").
Bob Rock
XmlArrayAttribute
参见参考:
http://msdn.microsoft.com/library/en ... ClassTopic.asp
和指南:
http://msdn.microsoft.com/library/en...attributes.asp
-Dino
ps:无需交叉发布
" Bob Rock" <无*************************** @ hotmail.com>在留言中写道
新闻:O3 ************* @ tk2msftngp13.phx.gbl ...
XmlArrayAttribute
see reference:
http://msdn.microsoft.com/library/en...ClassTopic.asp
and guide:
http://msdn.microsoft.com/library/en...attributes.asp
-Dino
ps: no need to cross-post
"Bob Rock" <no***************************@hotmail.com> wrote in message
news:O3*************@tk2msftngp13.phx.gbl...
你好,
使用XmlSerializer.Serialize()序列化类Classname的元素数组时,我得到如下的XML:
<?xml version =" 1.0" ;>
< ArrayOfClassname>
......
......
< / ArrayOfClassname>
我'我希望能够将XML根节点设置为与
< ArrayOfClassname>不同的东西。 ....例如类似< Classnames> ;.
作为替代XML时的替代方法,如下所示:
<?xml version =" 1.0">
< Classnames>
......
......
< / Classnames>
我想要能够加载它成为类
Classname的对象数组(在进行此类尝试的那一刻,我得到一个明显的例外
声明< Classnames>未被预期)。
Bob Rock
Hello,
when serializing an array of elements of a class Classname using
XmlSerializer.Serialize() I get an XML like the following:
<?xml version="1.0">
<ArrayOfClassname>
......
......
</ArrayOfClassname>
I''d like to be able to set the XML root node to something different from
<ArrayOfClassname> .... for example something like <Classnames>.
As an alternative when deserilizing an XML such as the following:
<?xml version="1.0">
<Classnames>
......
......
</Classnames>
I''d like to be able to "load" it into an array of objects of class Classname (at the moment when making such an attempt I get an obvious exception
stating "<Classnames> was not expected").
Bob Rock
" Dino Chiesa [Microsoft]" <二**** @ online.microsoft.com>写在消息
news:uz ************** @ TK2MSFTNGP10.phx.gbl ...
"Dino Chiesa [Microsoft]" <di****@online.microsoft.com> wrote in message
news:uz**************@TK2MSFTNGP10.phx.gbl...
XmlArrayAttribute
参考参考:
http://msdn.microsoft.com/library/en...ClassTopic.asp
和指南:
http://msdn.microsoft.com/library/en...attributes.asp
-Dino
ps:无需交叉
XmlArrayAttribute
see reference:
http://msdn.microsoft.com/library/en...ClassTopic.asp
and guide:
http://msdn.microsoft.com/library/en...attributes.asp
-Dino
ps: no need to cross-post
Dino,
我在Web方法中不是隐式使用Xmlserializer,而是在我的代码中明确地使用
。所以问题是,我如何应用XmlArrayAttribute ????
从文档中可以看出这*应该是*,但是如何???
很抱歉交叉发布,但只是希望更多
的人可以阅读(并希望回答)我的帖子。
Grazie mille。
Ciao,
Bob Rock
Dino,
I''m using Xmlserializer not implicitly within a web method but explicitly
within my code. So the question is, how do I apply the XmlArrayAttribute????
From the documentation is seems that this *should* be possible, but how???
Sorry for the cross-posting, but it is done only in the hope that more
people may read (and hopefully answer) my post.
Grazie mille.
Ciao,
Bob Rock
这篇关于使用XmlSerializer进行序列化:如何将XML根节点设置为与< ArrayOfClassname> ????不同的东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!