是否有一个的XElement相当于XmlWriter.WriteRaw?有一个、XElement、WriteRaw、XmlWriter

2023-09-03 05:45:40 作者:当幸福来敲门时

我将目前使用的一些code的的XmlWriter 来创建一个文件,而不是返回的XElement 的内容。

I'm converting some code that currently uses an XmlWriter to create a document to instead return an XElement of the content.

到目前为止,我很享受在构建code在模仿文档的结构方式,但被使用书面内容 XmlWriter.WriteRaw 以避免重新xmlizing的XML。我找不到在 System.Xml.Linq的命名空间的任何等价物。做一件存在吗?

So far, I'm enjoying structuring the code in a way that mimics the structure of the document, but there is content that was written using XmlWriter.WriteRaw to avoid re-xmlizing the xml. I can't find any equivalent in the System.Xml.Linq namespace. Does one exist?

推荐答案

XElement.Parse() 应该做的伎俩。

XElement.Parse() should do the trick.

例如:

XElement e = new XElement("root",
    new XElement("child",
        XElement.Parse("<big><blob><of><xml></xml></of></blob></big>"),
        new XElement("moreXml")));