By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,337 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,337 IT Pros & Developers. It's quick & easy.

Serializing a string as XML comments

P: n/a
Hello,

Does an attribute exist so that a string is serialized as a XML comment?

For example:

[XmlAttributeForCommentHere]
public string comment = "This is a comment";

which would serialize as:

<!--
This is a comment
-->
Thank you.
--
NoŽl
http://noeld.com/

Mar 29 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Hi Noel,

I'm pretty sure there isn't a way to do this using the XmlSerializer.
I'm not sure how it could be done as serialization is a two way process
and I'm not sure how you'd deserialize them.

I guess if you explained why you want to do this, we may be able to
offer a sensible alternative?

Josh
http://www.thejoyofcode.com/

Mar 29 '06 #2

P: n/a
Hi Josh,

Thanks for your reply. The code is part of a converter that would convert a
win.ini-like file to an .xml file, I wanted to pick the comments from the
ini file and to move them to the xml file.

Since most comments appear at the beginning of the file I will possibly have
to use the XmlWriter.WriteComment method.

Other suggestions are welcome. Thank you.
--
NoŽl
http://noeld.com/
Mar 29 '06 #3

P: n/a
You could just use extra nodes that are the comments maybe, since
they're data about the settings this mightn't be so bad? Here's a
totally made up example:

<settings>
<setting key="maxFileSize" value="240" description="comment here?">
</settings>

What do you think?

Josh
http://www.thejoyofcode.com/

Mar 29 '06 #4

P: n/a
Thanks for your suggestion, it would indeed work for commenting every
setting. For the main comments at the beginning of the file then I'd still
need to use WriteComment. I'll find a way to do that. Thanks for your
assistance.

--
NoŽl
http://noeld.com/
Mar 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.