XmlTextWriter.WriteElementString problem

  • Thread starter Thread starter fmancina
  • Start date Start date
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
 
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);
 
Frank,

Why not call WriteString after you write your attribute strings?

Hope this helps.
 
Back
Top