Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XmlWriter to write Element String with Attribute

Tags:

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> 
like image 720
Sanjay Avatar asked Jan 26 '12 21:01

Sanjay


1 Answers

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();                                  } 
like image 159
Raj Ranjhan Avatar answered Sep 17 '22 12:09

Raj Ranjhan