Search code examples
xmlvisual-studio-2008xmlwriter

formatting xml with xmltextwriter


I am creating xml docs using xmltextwriter ( by the way I was just introduced to xslt which I am now learning to adopt rather) and having problems getting the xml to indent correctly.

Here is what I would like the format to be

<htmltext> CData[.......<br>
   <img  src=".......">
   <a href="........"</a><br>
   ...some text here from a string....<br>
   ...some other text here froma string>
</htmltext>

here is what I have tried:

xwriter.WriteStartElement("htmltext")
xwriter.WriteCData(hcontent)
xwriter.WriteElementString("", "<br>")
xwriter.WriteString(Environment.NewLine)
xwriter.Indentation = 2
xwriter.WriteElementString("img", "")
xwriter.WriteStartAttribute("src", himage)
xwriter.WriteEndAttribute()
xwriter.WriteString(Environment.NewLine)
xwriter.WriteElementString("a", "")
xwriter.WriteStartAttribute("href", hlinks)
xwriter.WriteEndAttribute()
xwriter.WriteElementString("", htitle)
xwriter.WriteElementString("", "<br>")
xwriter.WriteString(Environment.NewLine)
xwriter.WriteElementString("", hsubtitle)
xwriter.WriteElementString("", "<br>")
xwriter.WriteString(Environment.NewLine)
xwriter.WriteElementString("", htext)
xwriter.WriteEndElement()

not sure where to go from here. Appreciate any responses


Solution

  • found a workaround and just converted all into a string.