Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 74485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:21:56+00:00 2026-05-10T20:21:56+00:00

When serializing/de-serializing certain classes I’ve come across the need to flag or mark certain

  • 0

When serializing/de-serializing certain classes I’ve come across the need to flag or mark certain properties as CDATA elements (due to their content). I am currently handling this like so:

    <XmlElement('MessageText')> _     Public Property XmlContentLeft() As XmlCDataSection         Get             Dim doc As New XmlDataDocument()             Dim cd As XmlCDataSection = doc.CreateCDataSection(Me.MessageText)             Return cd         End Get         Set(ByVal value As XmlCDataSection)             Me.MessageText = value.Value         End Set     End Property      <XmlIgnore()> _     Public Property MessageText() As String         Get             Return _messageText         End Get         Set(ByVal value As String)             _messageText= value         End Set     End Property 

Now while this works great it has drawbacks — I now have duplicate properties for anything I want to be a CDATA element and I have to write extra code for these properties.

So my question is whether or not there is a better way to do this? I don’t want to have to write custom schemas or serialization routines for each class. In an ideal scenario I’d be able to add an attribute to these properties so they are automatically treated as CDATA elements.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T20:21:57+00:00Added an answer on May 10, 2026 at 8:21 pm

    Two things:

    1) You can simplify your existing CDATA code like this:

    <XmlElement('MessageText')> _ Public Property XmlContentLeft() As XmlCDataSection     Get         return GetCData(Me.MessageText)     End Get     Set(ByVal value As XmlCDataSection)         Me.MessageText = value.Value     End Set End Property  ' this method is re-usable by any property that needs CData Private Function GetCData(ByVal value As String) As XmlCDataSection     Static doc As New XmlDataDocument()      return doc.CreateCDataSection(value) End Function  <XmlIgnore()> _ Public Property MessageText() As String     Get         Return _messageText     End Get     Set(ByVal value As String)         _messageText= value     End Set End Property 

    Of course that’s actually more code than you posted, but note that your CData property is now much simpler. Also, my use of Static isn’t a typo or C# mistake. VB.Net has a little-known Static keyword for creating members in functions. This way the XmlDataDocument is only created once for the entire class and doesn’t pollute your class’s private namespace.

    2) The serializer should already properly escapes character data. Do you really need it to be CData? Anything you serialize should be properly deserialized to match the original, even things like code strings. The only case I can thing where you might need a CDATA section is if you have to conform to a schema that’s expecting it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 61k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer See page 86 of the ACPI spec in relation to… May 11, 2026 at 9:40 am
  • added an answer You can express all those costs as a function of… May 11, 2026 at 9:40 am
  • added an answer And found an answer. rs = client.CreateObject('ADODB.Recordset') Needs to be:… May 11, 2026 at 9:40 am

Related Questions

When serializing/de-serializing certain classes I've come across the need to flag or mark certain
When serializing, I would like to serialize an object only once, then any references
Is it possible to avoid list property tags when serializing? //[Serializable()] - removed, unnecessary
I am serializing a class using simple-xml ( http://simple.sourceforge.net/ ) but when i try
When editing XAML in VS2008 SP1, the editor is really slow. devenv process seems
When should I include PDB files for a production release? Should I use the
When using jQuery 's ajax method to submit form data, what is the best
When spliting a solution in to logical layers, when is it best to use
When writing a switch statement, there appears to be two limitations on what you
When building a VS 2008 solution with 19 projects I sometimes get: The GenerateResource

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.