Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / January 2008

Tip: Looking for answers? Try searching our database.

Serializing an entity. I want a string property to come out as XML

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mike - 30 Jan 2008 15:01 GMT
I have a big entity class and I want one of the fields that calls a method to
return string xml to stay as xml after serialization.

IE:

[XmlElement("myelement")]
       public string Test
       {
           get{ return "<something></something>";  }      
           set { }
       }

When serialized will do:

<myelement>
<something>...etc
</myelement>

How do I tell it to force it as XML? The only way I could do it was by
making it return an xmlement, then in the GET: instantiate a new xmldocument,
make a new element, then populate that element innerxml with string xml.

Seems too ugly. Whats the right way??
Martin Honnen - 30 Jan 2008 15:42 GMT
> How do I tell it to force it as XML? The only way I could do it was by
> making it return an xmlement, then in the GET: instantiate a new xmldocument,
> make a new element, then populate that element innerxml with string xml.
>
> Seems too ugly. Whats the right way??

I don't think there is a better way, XmlElement is what you need and
unfortunately to create one you need an XmlDocument too.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/

Martin Honnen - 30 Jan 2008 16:55 GMT
> I don't think there is a better way, XmlElement is what you need and
> unfortunately to create one you need an XmlDocument too.

With .NET 3.5/Visual Studio 2008 you could also use an XElement and that
way you would not need an additional object as XElement can be created
without creating an XDocument.

Signature

    Martin Honnen --- MVP XML
    http://JavaScript.FAQTs.com/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.