Reputation: 399
I am using XmlWriter and I am wondering if some one ever tried to write the xml element string (leaf node) with attributes so that the output would look like
<book id='1' author='j.k.rowling' year='2010'>999</book>
instead of
<book id='1' author='j.k.rowling' year='2010'>
<book>999</book>
</book>
Upvotes: 24
Views: 64418
Reputation: 3917
You can use WriteString...
using (XmlWriter writer = XmlWriter.Create("books.xml"))
{
writer.WriteStartElement("book");
writer.WriteAttributeString("author", "j.k.rowling");
writer.WriteAttributeString("year", "1990");
writer.WriteString("99");
writer.WriteEndElement();
}
Upvotes: 62