xml反序列化 - 将子节点作为值 [英] xml deserialization - child nodes as value
问题描述
我正在尝试在xml上使用xml反序列化,例如:
I am trying to use xml deserialization on an xml like:
<ConfigurationFrag>
<Fragment>
<xml>
<theMore>
dsadas
</theMore>
morestrange
</xml>
job {
</Fragment>
<Fragment ImportConfigurationFrag="../${Location}scmDefinition.xml"/>
...
我希望得到:
...
and i would like to get:
<xml>
<theMore>
dsadas
</theMore>
morestrange
</xml>
job {
作为Fragment节点的值?
为此,我创建了xml序列化类: https://github.com/SavaNDragos/Agoc/ blob / master / pagox / agoc / Logic / Types / ConfigurationFrag.cs [ ^ ]
问题是我想使用xml反序列化:
as a value for the Fragment node?
For this I have created the xml serialization classes: https://github.com/SavaNDragos/Agoc/blob/master/pagox/agoc/Logic/Types/ConfigurationFrag.cs[^]
The problem is that I would like to use the xml deserialization:
var SerializerObj = new XmlSerializer(typeof(EnvironmentDef)); // we will do an xml serialization
var tempEnvironmentDef = (EnvironmentDef)SerializerObj.Deserialize(reader);
所以基本上有一种方法来反序列化xml那么子节点只是值吗?
So basically is there a way to deserialize an xml so can child nodes are just values?
推荐答案
{Location} scmDefinition.xml / >
{Location}scmDefinition.xml"/>
...
我希望得到:
...
and i would like to get:
<xml>
<theMore>
dsadas
</theMore>
morestrange
</xml>
job {
作为Fragment节点的值?
为此,我创建了xml序列化类:https://github.com/SavaNDragos/Agoc/blob/master/pagox/agoc/Logic/Types/ConfigurationFrag.cs [ ^ ]
问题是我想使用xml反序列化:
as a value for the Fragment node?
For this I have created the xml serialization classes: https://github.com/SavaNDragos/Agoc/blob/master/pagox/agoc/Logic/Types/ConfigurationFrag.cs[^]
The problem is that I would like to use the xml deserialization:
var SerializerObj = new XmlSerializer(typeof(EnvironmentDef)); // we will do an xml serialization
var tempEnvironmentDef = (EnvironmentDef)SerializerObj.Deserialize(reader);
所以基本上有一种方法来反序列化xml那么子节点只是值吗?
So basically is there a way to deserialize an xml so can child nodes are just values?
您的XML数据有点奇怪,但如果这是您想要的方式,我建议您将片段包装在CDATA部分中。这样,XML解析器将忽略该片段。
Your XML data is a bit weird, but if that is the way you want I suggest that you wrap the fragment in a CDATA section. That way an XML parser will ignore the fragment.
<ConfigurationFrag>
<Fragment>
<![CDATA[
<xml>
<theMore>
dsadas
</theMore>
morestrange
<xml>
job {
]]>
</Fragment>
<Fragment ImportConfigurationFrag="../
{Location} scmDefinition.xml / >
< / ConfigurationFrag >
{Location}scmDefinition.xml"/> </ConfigurationFrag>
这样可以更容易地使用标准XML序列化程序。
This should make it easier to use the standard XML serializer.
这篇关于xml反序列化 - 将子节点作为值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!