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

XmlWriter Question

P: n/a
Hi,

I am using XMLWriter to build xml and I need to build the element below.
How do I do this?

<Password format="encrypted">password</Password>

Thanks
Sep 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Harry <ha***@harryspam.comwrote:
I am using XMLWriter to build xml and I need to build the element below.
How do I do this?

<Password format="encrypted">password</Password>
Try this:

using System;
using System.Xml;

class Test
{
static void Main()
{
XmlWriter writer = new XmlTextWriter(Console.Out);

writer.WriteStartDocument();
writer.WriteStartElement("Password");
writer.WriteAttributeString("format", "encrypted");
writer.WriteString("password");
writer.WriteEndElement();
writer.WriteEndDocument();
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 28 '06 #2

P: n/a
Hi Harry,

Try This

public static void CreateXML2()
{
StringWriter stringWriter = new StringWriter();
XmlTextWriter xmlWriter = new XmlTextWriter(stringWriter);
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Password");
xmlWriter.WriteAttributeString("format", "encrypted");
xmlWriter.WriteValue("password");
xmlWriter.WriteEndDocument();
xmlWriter.Close();
Console.WriteLine(stringWriter.ToString());
}

Regards,
Nick

Harry wrote:
Hi,

I am using XMLWriter to build xml and I need to build the element below.
How do I do this?

<Password format="encrypted">password</Password>

Thanks
Sep 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.