Click here to Skip to main content
15,917,709 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to use xml deserialization on an xml like:

XML
<ConfigurationFrag>
  <Fragment>
    <xml>
      <theMore>
        dsadas
      </theMore>
      morestrange
    </xml>
    job {
  </Fragment>
  <Fragment ImportConfigurationFrag="../${Location}scmDefinition.xml"/>

...
and i would like to get:

XML
<xml>
    <theMore>
        dsadas
    </theMore>
    morestrange
</xml>
job {


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:

C#
var SerializerObj = new XmlSerializer(typeof(EnvironmentDef)); // we will do an xml serialization
          var tempEnvironmentDef = (EnvironmentDef)SerializerObj.Deserialize(reader);


So basically is there a way to deserialize an xml so can child nodes are just values?
Posted
Updated 1-Nov-15 13:21pm
v3
Comments
Sergey Alexandrovich Kryukov 1-Nov-15 15:53pm    
The problem is not clear. What have you tried so far?
—SA

1 solution

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.

XML
<ConfigurationFrag>
    <Fragment>
        <![CDATA[
            <xml>
                <theMore>
                    dsadas
                </theMore>
                morestrange
            <xml>
            job {
        ]]>
    </Fragment>
    <Fragment ImportConfigurationFrag="../${Location}scmDefinition.xml"/>
</ConfigurationFrag>

This should make it easier to use the standard XML serializer.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900