JMK
JMK

Reputation: 28059

C# WriteAttributeString - Multiple Elements

I'm using System.Xml to create an XML document. I need to create something similar to the following:

<Communication primary="N" value="[email protected]" purpose="PERSONAL" type="EMAIL"/>

I can use 'WriteAttributeString' to get as far as this:

<Communication primary="N"/>

The problem is it won't let me add any more attributes and I'm a bit stuck. Any help/advice would be much appreciated.

Edit: The code is below to create the above XML:

writer.WriteStartElement("CommunicationList");

writer.WriteStartElement("Communication");
writer.WriteAttributeString("primary", "N");
writer.WriteEndElement();

writer.WriteEndElement();

I need to add the 'Value', 'Purpose' and 'Type' attributes to this and I'm at a loss.

Thanks

Upvotes: 2

Views: 8225

Answers (1)

Rickard
Rickard

Reputation: 2335

This should render what you want:

writer.WriteStartElement("CommunicationList");

writer.WriteStartElement("Communication");
writer.WriteAttributeString("primary", "N");
writer.WriteAttributeString("value", "[email protected]");
writer.WriteAttributeString("purpose", "PERSONAL");
writer.WriteAttributeString("type", "EMAIL");
writer.WriteEndElement();

writer.WriteEndElement();

Upvotes: 6

Related Questions