开发者

C# WriteAttributeString - Multiple Elements

开发者 https://www.devze.com 2023-04-08 04:34 出处:网络
I\'m using System.Xml to create an XML document. I need to create something similar to the following:

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

<Communication primary="N" value="heisenburg@albuquerquecarwash.com" purpose="PERSONAL" type="EMAIL"/>

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

<Communication primary="N"/>
开发者_C百科

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


This should render what you want:

writer.WriteStartElement("CommunicationList");

writer.WriteStartElement("Communication");
writer.WriteAttributeString("primary", "N");
writer.WriteAttributeString("value", "heisenburg@albuquerquecarwash.com");
writer.WriteAttributeString("purpose", "PERSONAL");
writer.WriteAttributeString("type", "EMAIL");
writer.WriteEndElement();

writer.WriteEndElement();
0

精彩评论

暂无评论...
验证码 换一张
取 消