本文整理汇总了C#中System.Xml.Linq.XDocument.ToXmlDocument方法的典型用法代码示例。如果您正苦于以下问题:C# XDocument.ToXmlDocument方法的具体用法?C# XDocument.ToXmlDocument怎么用?C# XDocument.ToXmlDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XDocument
的用法示例。
在下文中一共展示了XDocument.ToXmlDocument方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCraigslistJobDetails
public XmlNode GetCraigslistJobDetails( XPathNodeIterator input )
{
input.MoveNext();
var body = input.Current.OuterXml;
var resultDocument = new XDocument();
var resultElement = body.GetDetails();
resultDocument.Add( resultElement );
var result = resultDocument.ToXmlDocument().FirstChild;
return result;
}
示例2: CheckXml
/// <summary>
/// Check an XElement against some expected XML.
/// <para>
/// The supplied node is copied and normalized to get actual differences.
/// </para>
/// </summary>
/// <param name="expected">XElement to use</param>
/// <param name="candidate">XML to compare against.</param>
/// <param name="fullComparison">Whether to do a full comparison using prefix/namespace</param>
/// <param name="diffFilePath">Where/whether to write out the HTML difference</param>
public static string CheckXml(this XElement expected, XElement candidate, bool fullComparison = true, string diffFilePath = "")
{
// Xml's are normalized before comparision, so that we can get actual difference when we turn on Namespaces & Prefix's differnces
var source = new XDocument(expected);
source = source.Normalize();
var expectedNode = source.ToXmlDocument().SelectSingleNode("/*");
var target = new XDocument(candidate);
target = target.Normalize();
var candidateNode = target.ToXmlDocument().SelectSingleNode("/*");
using (var stringWriter = new StringWriter())
{
bool areDifferent;
using (var xmlWriter = new XmlTextWriter(stringWriter) { Formatting = Formatting.Indented })
{
// Default engine ignores prefix/namespace so we need to enable if we are doing a full comparison.
var diff = DefaultDiffEngine();
diff.IgnorePrefixes = !fullComparison;
diff.IgnoreNamespaces = !fullComparison;
areDifferent = !diff.Compare(expectedNode, candidateNode, xmlWriter);
}
if (areDifferent)
{
if (!string.IsNullOrEmpty(diffFilePath))
{
var diffgram = stringWriter.GetStringBuilder().ToString();
WriteDiffFile(diffFilePath, diffgram, expectedNode);
}
return string.Format(
"Xml differs.{0}Expected:{0}{1}{0}{0}Actual:{0}{2}{0}{0}Diff:{0}{3}",
Environment.NewLine,
expectedNode.ToXmlString(),
candidateNode.ToXmlString(),
stringWriter);
}
}
return string.Empty;
}
示例3: Rsd
public HttpResponseMessage Rsd()
{
XNamespace ns = XNamespace.Get("http://archipelago.phrasewise.com/rsd");
XDocument response = new XDocument(
new XElement(ns + "service",
new XElement(ns + "engineName", "Dexter Blog Engine"),
new XElement(ns + "engineLink", "http://www.dexterblogengine.com"),
new XElement(ns + "homePageLink", this.urlBuilder.Home),
new XElement(ns + "apis",
new XElement(ns + "api",
new XAttribute("name", "MetaWeblog"),
new XAttribute("preferred", "true"),
new XAttribute("blogID", "0"),
new XAttribute("apiLink", this.urlBuilder.Service.MetaWebLogApi())))));
return new HttpResponseMessage
{
Content = new XmlContent(response.ToXmlDocument())
};
}