本文整理汇总了C#中System.Xml.XPath.XPathNavigator.ReplaceSelf方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.ReplaceSelf方法的具体用法?C# XPathNavigator.ReplaceSelf怎么用?C# XPathNavigator.ReplaceSelf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.ReplaceSelf方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessItemGroupNode
private static bool ProcessItemGroupNode(XPathNavigator nav)
{
try
{
if (nav.MoveToChild("StyleCopTreatErrorsAsWarnings", "http://schemas.microsoft.com/developer/msbuild/2003"))
{
if (nav.Value == "false")
{
nav.ReplaceSelf("<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>");
}
else
{
nav.ReplaceSelf("<StyleCopTreatErrorsAsWarnings>false</StyleCopTreatErrorsAsWarnings>");
}
}
else
{
nav.AppendChild("<StyleCopTreatErrorsAsWarnings>true</StyleCopTreatErrorsAsWarnings>");
}
return true;
}
catch
{
return false;
}
}
示例2: WriteObject
public bool WriteObject(XPathResult result, XPathNavigator node, object value)
{
var xml = new StringBuilder();
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = false
};
using (var writer = XmlWriter.Create(xml, settings))
{
if (value is IXmlSerializable)
{
SerializeCustom(writer, result, node, (IXmlSerializable)value);
}
else
{
Serialize(writer, result, node, value);
}
writer.Flush();
}
node.ReplaceSelf(xml.ToString());
return true;
}
示例3: WriteObject
public bool WriteObject(XPathResult result, XPathNavigator node, object value)
{
var rootOverride = new XmlRootAttribute(node.LocalName)
{
Namespace = node.NamespaceURI
};
var xml = new StringBuilder();
var settings = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = false
};
var namespaces = new XmlSerializerNamespaces();
namespaces.Add(string.Empty, string.Empty);
if (string.IsNullOrEmpty(node.NamespaceURI) == false)
{
var prefix = result.Context.AddNamespace(node.NamespaceURI);
namespaces.Add(prefix, node.NamespaceURI);
}
var serializer = new XmlSerializer(result.Type, rootOverride);
using (var writer = XmlWriter.Create(xml, settings))
{
serializer.Serialize(writer, value, namespaces);
writer.Flush();
}
node.ReplaceSelf(xml.ToString());
return true;
}