0

I want to use XML serialization to de-serialize this HTML structures.

When I deserialize this structure, the H3 object has a content of Test Before and a child node containing <span class="red">Small</span>, but the value of Test After is lost

The following structure is valid in XHTML, though its possibly not valid in XML.

I know someone else asked a similar question here, C# how to deserialize an xml tag embedded in text but they did NOT receive an working answer to their problem.

    <div class="row-fluid">
      <h3>Test Before <span class="red">Small</span> Test After</h3>
      <h4>Header and Footer</h4>
    </div>

I know that a workable option would be as follows, but I'm hopping someone has a better technique that uses the XML serializer

    <div class="row-fluid">
      <h3><![CDATA[[Test Before <span class="red">Small</span> Test After]]></h3>
      <h4>Header and Footer</h4>
    </div>

Here are some samples of my XML serialization objects

All objects derive from

public abstract class BaseSlideDeckNodeDo
{
    protected BaseSlideDeckNodeDo()
    {
        CssClass = "";

        Nodes = new List<BaseSlideDeckNodeDo>();
    }

    [XmlAttribute("id")]
    public string Id { get; set; }

    [XmlAttribute("class")]
    public string CssClass { get; set; }

    [XmlAttribute("style")]
    public string Style { get; set; }

    [XmlText]
    public string Text { get; set; }


    [XmlElement("a", typeof(SlideDeckNodeADo))]
    [XmlElement("div", typeof(SlideDeckNodeDivDo))]
    [XmlElement("p", typeof(SlideDeckNodePDo))]
    [XmlElement("h1", typeof(SlideDeckNodeH1Do))]
    [XmlElement("h2", typeof(SlideDeckNodeH2Do))]
    [XmlElement("h3", typeof(SlideDeckNodeH3Do))]
    [XmlElement("h4", typeof(SlideDeckNodeH4Do))]
    [XmlElement("h5", typeof(SlideDeckNodeH5Do))]
    [XmlElement("h6", typeof(SlideDeckNodeH6Do))]
    [XmlElement("img", typeof(SlideDeckNodeImageDo))]
    [XmlElement("iframe", typeof(SlideDeckNodeIframeDo))]
    [XmlElement("video", typeof(SlideDeckNodeVideoDo))]
    [XmlElement("html", typeof(SlideDeckNodeHtmlDo))]
    [XmlElement("section", typeof(SlideDeckNodeSectionDo))]
    [XmlElement("span", typeof(SlideDeckNodeSpanDo))]
    public List<BaseSlideDeckNodeDo> Nodes { get; set; }
}

Example of H3 class

public class SlideDeckNodeH3Do : BaseSlideDeckAnimatedNodeDo
{
}

Example of the Span class

public class SlideDeckNodeSpanDo : BaseSlideDeckAnimatedNodeDo
{
}
Community
  • 1
  • 1
David Cruwys
  • 6,262
  • 12
  • 45
  • 91
  • What exactly are you trying to achieve? What object structure would you like to deserialize into? – John Saunders Aug 27 '13 at 01:07
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Aug 27 '13 at 01:07
  • @DavidSee, I have a similar requirement where my xml file contains data like `

    Starbucks

    Embedded image


    `. I have no control over this file as I am receiving this file from other sources. Now while deserializing using XmlSerializer, I am facing problem. Did you get any solution? Should I implement IXmlSerializable? Could you please guide me?
    – user3282758 Aug 30 '14 at 11:50

0 Answers0