Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The point of object serialization is to save the state of an object, and restore it later. Object fields are mapped to XML elements and attributes, and vice versa. XMLSerializer does not map anything to comments or vice versa, so you can't deserialize comments to anything in your object.</p> <p>However if you use an XmlReader (as @Amigable said) which you pass to the <a href="http://msdn.microsoft.com/en-us/library/tz8csy73.aspx" rel="nofollow">Deserialize</a>() method, you can then use that <a href="http://msdn.microsoft.com/en-us/library/cc189056%28VS.95%29.aspx" rel="nofollow">XmlReader to separately traverse the tree</a> looking for comments.</p> <p>Unfortunately this makes it harder to connect the comments to the deserialized members, but maybe you could use deserialization node event handlers to help with that.</p> <p><strong>Update:</strong> a little elaboration on using an XmlReader with Deserialize:</p> <p>You listed your code as:</p> <pre><code>XmlSerializer objSer = new XmlSerializer(typeof(CustomSchema)); StreamReader srmRdr = new StreamReader("Test.XML"); objForm = (CustomSchema)objSer.Deserialize(srmRdr); </code></pre> <p>I don't know anything about .NETCF or WM. (I didn't know anything about XmlSerializer either but I'm just looking at <a href="http://msdn.microsoft.com/en-us/library/w8k674bf%28v=VS.95%29.aspx" rel="nofollow">the docs</a>.) However here's what I was trying to describe above.</p> <p>I thought you could use an XmlReader for Deserialize() and then re-use it, but apparently it's forward-only and therefore can't be reset to the beginning. So After your deserialization, re-open "Test.XML" with an XmlReader:</p> <pre><code>XmlReader xmlRdr = XmlReader.Create("Test.XML"); </code></pre> <p>Then use the parsing <a href="http://msdn.microsoft.com/en-us/library/cc189056%28VS.95%29.aspx" rel="nofollow">code shown here</a>:</p> <pre><code> // Parse the file while (xmlRdr.Read()) { switch (xmlRdr.NodeType) { case XmlNodeType.Element: // You may need to capture the last element to provide a context // for any comments you come across... so copy xmlRdr.Name, etc. break; case XmlNodeType.Comment: // Do something with xmlRdr.value </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload