开发者

Adding tags to textwriter?

开发者 https://www.devze.com 2022-12-10 00:12 出处:网络
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

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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号