本文整理汇总了C#中System.Xml.Linq.XNode.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# XNode.ToString方法的具体用法?C# XNode.ToString怎么用?C# XNode.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.Linq.XNode
的用法示例。
在下文中一共展示了XNode.ToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CleanCData
private string CleanCData(XNode xNode)
{
if (xNode is XCData)
{
XCData xdata = (XCData)xNode;
return StripDiv( xdata.Value );
}
return xNode.ToString();
}
示例2: GetDiff
public static string GetDiff(XNode expected, XNode actual, string diffResult = null)
{
if (diffResult == null) diffResult = "";
if (IsBasicNode(expected) && IsBasicNode(actual))
{
if (!expected.ToString().Equals(actual.ToString()))
{
diffResult = String.Format("{0}{1} has different value:\r\n Expected: {2}\r\n But was: {3}\r\n\r\n",
diffResult, ((XElement)actual).Name.LocalName, expected.ToString(), actual.ToString());
}
return diffResult;
}
var expectedChildren = ((XElement)expected).Descendants().OrderBy(e => e.Name.LocalName).ToList();
var actualChildren = ((XElement)actual).Descendants().OrderBy(a => a.Name.LocalName).ToList();
var missingChildren = expectedChildren.Where(e => actualChildren.Where(a => e.Name == a.Name).Count() == 0);
foreach (var missingChild in missingChildren)
{
diffResult = String.Format("{0}{1} has missing Property:\r\n {2}\r\n\r\n", diffResult, ((XElement)actual).Name.LocalName, missingChild.Name.LocalName);
}
var extraChildren = actualChildren.Where(a => expectedChildren.Where(e => a.Name == e.Name).Count() == 0);
foreach (var extraChild in extraChildren)
{
diffResult = String.Format("{0}{1} has extra Property:\r\n {2}\r\n\r\n", diffResult, ((XElement)actual).Name.LocalName, extraChild.Name.LocalName);
}
foreach (var actualChild in actualChildren)
{
foreach (var expectedChild in expectedChildren)
{
if (expectedChild.Name.LocalName.Equals(actualChild.Name.LocalName, StringComparison.OrdinalIgnoreCase))
{
diffResult = GetDiff(expectedChild, actualChild, diffResult);
break;
}
}
}
//return diffResult;
return "";
}
示例3: UnescapeContent
private static string UnescapeContent(XNode node)
{
var reader = new StringReader(node.ToString());
var settings = new XmlReaderSettings {
ConformanceLevel = ConformanceLevel.Fragment
};
using (var xmlReader = XmlReader.Create(reader, settings)) {
xmlReader.MoveToContent ();
return xmlReader.ReadString();
}
}
示例4: WriteNode
protected void WriteNode(XNode node, TextWriter writer, DocItemWriterContext context)
{
if (node is XText || node is XCData)
{
WriteHyperlinkEnabledText(node.ToString(), writer, context);
return;
}
XElement element = node as XElement;
if (element != null)
{
switch (element.Name.ToString())
{
case "see":
{
string cref = element.Attribute("cref").Value;
string text = element.Value;
WriteHyperlinkSymbol(cref, text, writer, context);
}
return;
}
}
throw new ArgumentException(string.Format("[{0}]: Don't know how to print {1}.", this.AssociatedDocItem.Name, node.GetType().Name));
}
示例5: Markup
/// <summary>
/// Renders the specified XNode.
/// </summary>
/// <param name="xNode">The <see cref="XNode">XNode</see>.</param>
/// <returns></returns>
public IHtmlString Markup(XNode xNode)
{
if (xNode == null)
{
return null;
}
// TODO: optimize so XNode doesn't get serialized/deserialized
return _helper.Raw(xNode.ToString());
}
示例6: parseXml
private string parseXml(XNode root, int tabs)
{
string result = "<br />";
if (root != null)
{
for (int i = 0; i < tabs; i++)
{
result += " ";
}
result += root.ToString();
}
for (int i = 0; i < root.NodesAfterSelf().Count(); i++)
{
result += parseXml(root.NodesAfterSelf().ElementAt(i), tabs + 1);
}
return result;
}
示例7: ChunkXml
protected IEnumerable<OutputChunk> ChunkXml(XNode node)
{
return ChunkString(node.ToString(SaveOptions.DisableFormatting));
}
示例8: GetReplacementValueFromEvent
private string GetReplacementValueFromEvent(ReplacementEvent replacementEvent, XNode foundNode)
{
// may be a bug .... ex: with two view-selection under action performed
List<NodeAndAttributeCouple> replaceableValues = GetReplacementParametersFromValue(replacementEvent.Value);
string completedEvent = replacementEvent.Value;
XElement element = XElement.Parse(foundNode.ToString());
for (int i = 0; i < replaceableValues.Count; i++) {
if (string.Equals(replaceableValues[i].attrName, "TextValue", StringComparison.InvariantCultureIgnoreCase)) {
string textValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).ElementAt(0).Value.Trim();
if (completedEvent.Contains("{" + replaceableValues[i].nodeName + ":TextValue}")) {
completedEvent = completedEvent.Replace("{" + replaceableValues[i].nodeName + ":TextValue}", textValue);
} else {
completedEvent = completedEvent.Replace("{TextValue}", textValue);
}
} else {
if (element.DescendantsAndSelf(replaceableValues[i].nodeName).Attributes(replaceableValues[i].attrName).Count() >= replaceableValues[i].index) {
string attrValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).Attributes(replaceableValues[i].attrName).ElementAt(replaceableValues[i].index).Value.Trim();
if (completedEvent.Contains("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrName + "}")) {
completedEvent = completedEvent.Replace("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrName + "}", attrValue);
} else if (completedEvent.Contains("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrNameWithAt + "}")) {
completedEvent = completedEvent.Replace("{" + replaceableValues[i].nodeName + ":" + replaceableValues[i].attrNameWithAt + "}", attrValue);
} else if (completedEvent.Contains("{" + replaceableValues[i].attrName + "}")) {
completedEvent = completedEvent.Replace("{" + replaceableValues[i].attrName + "}", attrValue);
}
}
}
}
return completedEvent;
}
示例9: GetParametrizedRepFromGenericOne
private string GetParametrizedRepFromGenericOne(ReplacementEvent replacementEvent, XNode xNode)
{
// may be a bug .... ex: with two view-selection under action performed
List<NodeAndAttributeCouple> replaceableValues = GetReplacementParametersFromValue(replacementEvent.Value);
string completedEvent = replacementEvent.Value;
XElement element = XElement.Parse(xNode.ToString());
for (int i = 0; i < replaceableValues.Count; i++) {
if (string.Equals(replaceableValues[i].attrName, "TextValue", StringComparison.InvariantCultureIgnoreCase)) {
string textValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).ElementAt(0).Value;
completedEvent = completedEvent.Replace("{TextValue}", textValue);
} else {
string attrValue = element.DescendantsAndSelf(replaceableValues[i].nodeName).Attributes(replaceableValues[i].attrName).ElementAt(0).Value;
completedEvent = completedEvent.Replace("{" + replaceableValues[i].attrName + "}", attrValue);
}
}
return completedEvent;
}
示例10: PrepareRequest
/// <summary>
/// Prepares the request based on the parameters.
/// </summary>
/// <param name="uri">
/// The uri.
/// </param>
/// <param name="method">
/// The method.
/// </param>
/// <param name="content">
/// The content.
/// </param>
/// <param name="contentType">
/// The content type.
/// </param>
/// <param name="timeoutMs">
/// The timeout milliseconds.
/// </param>
/// <returns>
/// The <see cref="WebRequest"/>.
/// </returns>
private static WebRequest PrepareRequest(string uri, string method, XNode content, string contentType, int timeoutMs)
{
WebRequest request = WebRequest.Create(uri);
request.Method = method;
request.AuthenticationLevel = AuthenticationLevel.None;
request.ImpersonationLevel = TokenImpersonationLevel.Anonymous;
request.Timeout = timeoutMs;
if (content != null)
{
string postData = content.ToString();
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = contentType;
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
}
return request;
}
示例11: SendCore
private void SendCore(XNode element)
{
SendCore(element.ToString(SaveOptions.DisableFormatting));
}
示例12: ToPreviewString
private string ToPreviewString(XNode node)
{
if (node == null) return string.Empty;
if (node is XElement)
{
var sbResult = new StringBuilder();
foreach (var childNode in (node as XElement).Nodes())
{
sbResult.Append(ToPreviewString(childNode));
}
return sbResult.ToString();
}
return node.ToString();
}