Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As a response to your comment about modifying it in memory:</p> <p>Consider writing a schema like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:complexType name="FromType"&gt; &lt;xs:attribute name="Address" type="xs:string"/&gt; &lt;/xs:complexType&gt; &lt;xs:simpleType name="RecipientMethod"&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:enumeration value="To"/&gt; &lt;xs:enumeration value="Cc"/&gt; &lt;xs:enumeration value="Bcc"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;xs:complexType name="RecipientType"&gt; &lt;xs:attribute name="Type" type="RecipientMethod"/&gt; &lt;xs:attribute name="Address" type="xs:string"/&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="Email"&gt; &lt;xs:sequence&gt; &lt;xs:element name="From" type="FromType" minOccurs="1" maxOccurs="1"/&gt; &lt;xs:element name="Recipient" type="RecipientType" minOccurs="1" maxOccurs="unbounded"/&gt; &lt;xs:element name="Subject" type="xs:string" minOccurs="0" maxOccurs="1"/&gt; &lt;xs:element name="Body" type="xs:string" minOccurs="0" maxOccurs="1"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:complexType name="Emails"&gt; &lt;xs:sequence&gt; &lt;xs:element name="Emails" type="Email" minOccurs="1" maxOccurs="unbounded"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;xs:element name="Emails" type="Emails"/&gt; &lt;/xs:schema&gt; </code></pre> <p>and run the schema compiler xsd.exe on it (<a href="http://msdn.microsoft.com/en-us/library/x6c1kb0s.aspx" rel="nofollow noreferrer">here</a>) </p> <p>With the class it generates, you just set the members, like this:</p> <pre><code>Emails e= new Emails(); e.Email = new Email[2]; e.Email[0] = new Email(); e.Email[0].From = new FromType(); ... </code></pre> <p>Once the members are set, then do this:</p> <pre><code>FileStream f ... XmlSerializer x = new XmlSerializer( e, f ); x.Serialize(e); </code></pre> <p>Similarly, you can deserialize:</p> <pre><code>Emails ne = x.DeSerialize(); </code></pre> <p>Then modify it to add a new Email:</p> <pre><code>Email newEmail = Email[ne.Email.Length + 1]; for(int i = 0; i &lt; ne.Email.Length; i++) newEmail[i] = ne.Email[i]; newEmail[ne.Email.Length] = new Email(); .... ne.Email = newEmail; </code></pre> <p>then serialize it back.</p>
 

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