本文整理匯總了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;
}