Adding tags to textwriter?
How do I add an <abc>
tag in a start and </abc>
开发者_运维问答tag in end tag in textwriter?
Use an XmlWriter
. Write your starting root element. Then pass the XmlWriter
to the XSL transform. It will continue writing. When that's done, write your end root element:
public static void WrapTransform(
Stream outputStream,
string styleSheetUri,
string documentUri)
{
var transform = new XslCompiledTransform();
using (var styleSheetReader = XmlReader.Create(styleSheetUri))
{
transform.Load(styleSheetReader);
}
using (var wrapper = XmlWriter.Create(outputStream))
{
wrapper.WriteStartElement("Root");
transform.Transform(documentUri, wrapper);
wrapper.WriteEndElement();
}
}
精彩评论