Deserialization With XML Elements That Contain HTML

G

Guest

Hello,
I was wondering if there is a way to have the contents of an XML element
that contains HTML to be deserialized into the cooresponding string property
without the HTML tags being surronded by CDATA?

<?xml version="1.0" encoding="UTF-8" ?>
<introduction>
<header>
<h1>Helping you achieve the natural look you want</h1>
</header>
<text>
<p> The comprehensive resource connecting you with reliable
infor..</p>
</text>
</introduction>

Deserialize into:

[System.Xml.Serialization.XmlRootAttribute(ElementName=Constant.IntroductionElement, Namespace = "", IsNullable = false) ]
public class Introduction
{
//Private variables.
private string _header = string.Empty;
private string _text = string.Empty;

[System.Xml.Serialization.XmlElementAttribute(Constant.HeaderElement)]
public string Header
{
get
{
return this._header;
}
set
{
this._header = value;
}
}

[System.Xml.Serialization.XmlElementAttribute(Constant.TextElement)]
public string Text
{
get
{
return this._text;
}
set
{
this._text = value;
}
}

}

I want the properties of the above class when returned to contain the HTML
tags but I cannot use CDATA around those tags.

Any help will be very much appreciated.
Thanks,
Ken
 
G

Guest

The serialization attribute is a .NET provided attribute. I have not seen a
way of specifiying the InnerHTML or InnerXML property.

John Bailo said:
Can you add the InnerHTML property to your serialization attribute?
Hello,
I was wondering if there is a way to have the contents of an XML element
that contains HTML to be deserialized into the cooresponding string property
without the HTML tags being surronded by CDATA?

<?xml version="1.0" encoding="UTF-8" ?>
<introduction>
<header>
<h1>Helping you achieve the natural look you want</h1>
</header>
<text>
<p> The comprehensive resource connecting you with reliable
infor..</p>
</text>
</introduction>

Deserialize into:

[System.Xml.Serialization.XmlRootAttribute(ElementName=Constant.IntroductionElement, Namespace = "", IsNullable = false) ]
public class Introduction
{
//Private variables.
private string _header = string.Empty;
private string _text = string.Empty;

[System.Xml.Serialization.XmlElementAttribute(Constant.HeaderElement)]
public string Header
{
get
{
return this._header;
}
set
{
this._header = value;
}
}

[System.Xml.Serialization.XmlElementAttribute(Constant.TextElement)]
public string Text
{
get
{
return this._text;
}
set
{
this._text = value;
}
}

}

I want the properties of the above class when returned to contain the HTML
tags but I cannot use CDATA around those tags.

Any help will be very much appreciated.
Thanks,
Ken
 
L

Larry Lard

Kenneth said:
Hello,
I was wondering if there is a way to have the contents of an XML element
that contains HTML to be deserialized into the cooresponding string property
without the HTML tags being surronded by CDATA?

<?xml version="1.0" encoding="UTF-8" ?>
<introduction>
<header>
<h1>Helping you achieve the natural look you want</h1>
</header>
<text>
<p> The comprehensive resource connecting you with reliable
infor..</p>
</text>
</introduction>

Deserialize into:

[System.Xml.Serialization.XmlRootAttribute(ElementName=Constant.IntroductionElement, Namespace = "", IsNullable = false) ]
public class Introduction
{
//Private variables.
private string _header = string.Empty;
private string _text = string.Empty;

[System.Xml.Serialization.XmlElementAttribute(Constant.HeaderElement)]
public string Header
{
get
{
return this._header;
}
set
{
this._header = value;
}
}

[System.Xml.Serialization.XmlElementAttribute(Constant.TextElement)]
public string Text
{
get
{
return this._text;
}
set
{
this._text = value;
}
}

}

I want the properties of the above class when returned to contain the HTML
tags but I cannot use CDATA around those tags.


I'd say you are going to have to do custom deserialization - implement
IXmlSerializable on Introduction and in the ReadXml method, just get the
InnerText (probably) of the element.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top