XmlTextWriter.WriteElementString problem

F

fmancina

Hi,

I am employing the XmlTextWriter class to generate an XML document.
Everything works fine, until I have to write an attribute to an element
which contains a value.

Examples below:

// <Author>Frank</Author>
// is equivalent to
writer.WriteElementString("Author","Frank");

// <Font ss:FontName="Verdana" ss:Size="12" ss:Bold="1"/>
// is equivalent to
writer.WriteStartElement("Font");
writer.WriteAttributeString("ss:FontName", "Verdana");
writer.WriteAttributeString("ss:Size", "12");
writer.WriteAttributeString("ss:Bold", "1");
writer.WriteEndElement();

However, if I wanted to do this:

//<Data ss:Type="String">sample data</Data>

I cannot.

Does anyone know if there is a way to write attributes on elements that
contain a string value?

Thanks for any help,

Frank
 
F

fmancina

Just for clarity,

Let me define the writer variable:

// StringWriter to write the strings
StringWriter writerString = new StringWriter();

// XmlTextWriter to create the XML
XmlTextWriter writer = new XmlTextWriter(writerString);
 
N

Nicholas Paldino [.NET/C# MVP]

Frank,

Why not call WriteString after you write your attribute strings?

Hope this helps.
 

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

Top