XmlWriter Question

  • Thread starter Thread starter Harry
  • Start date Start date
H

Harry

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
 
Harry said:
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();
}
}
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top