简体   繁体   中英

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

找到了解决方法,然后将其全部转换为字符串。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM