本文整理汇总了C#中System.Xml.XPath.XPathNavigator.CreateAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.CreateAttribute方法的具体用法?C# XPathNavigator.CreateAttribute怎么用?C# XPathNavigator.CreateAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.CreateAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetOrCreateXmlAttribute
public static void SetOrCreateXmlAttribute(XPathNavigator node, string localName, string namespaceURI, string value)
{
if (node.MoveToAttribute(localName, namespaceURI))
{
node.SetValue(value);
node.MoveToParent();
}
else
{
node.CreateAttribute("", localName, namespaceURI, value);
}
}
示例2: SetXmlType
public void SetXmlType(string name, string namespaceUri, XPathNavigator source)
{
namespaceUri = GetEffectiveNamespace(namespaceUri);
var prefix = CreateNamespace(null, namespaceUri, source);
source.CreateAttribute("xsi", "type", Xsi, GetQualifiedName(prefix, name));
}
示例3: CreateAttribute
public XPathNavigator CreateAttribute(string name, string namespaceUri, XPathNavigator source)
{
source.CreateAttribute(null, name, namespaceUri, "");
source.MoveToAttribute(name, namespaceUri ?? "");
return source;
}
示例4: CreateNamespace
public string CreateNamespace(string prefix, string namespaceUri, XPathNavigator source)
{
if (string.IsNullOrEmpty(namespaceUri) == false)
{
source = source.Clone();
source.MoveToRoot();
source.MoveToChild(XPathNodeType.Element);
if (string.IsNullOrEmpty(prefix))
prefix = AddNamespace(namespaceUri);
var existing = source.GetNamespace(prefix);
if (existing == namespaceUri) return prefix;
if (string.IsNullOrEmpty(existing) == false) return null;
source.CreateAttribute("xmlns", prefix, "", namespaceUri);
}
return prefix;
}
示例5: NormalizeNamespaces
private static void NormalizeNamespaces(XPathNavigator src, XPathNavigator dest) {
IDictionary<string, string> dictLocal = src.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml);
IDictionary<string, string> dictExclude = dest.GetNamespacesInScope(XmlNamespaceScope.Local);
foreach(KeyValuePair<string, string> pair in dictLocal)
if(!dictExclude.ContainsKey(pair.Key))
dest.CreateAttribute("xmlns", pair.Key, "http://www.w3.org/2000/xmlns/", pair.Value);
}
示例6: MakeNil
public bool MakeNil(XPathNavigator source)
{
if (source.NodeType == XPathNodeType.Element && IsNil(source) == false)
{
source.CreateAttribute("xsi", "nil", Xsi, "true");
return true;
}
return false;
}
示例7: CreateAttribute
public XPathNavigator CreateAttribute(string name, string namespaceUri, XPathNavigator source)
{
name = XmlConvert.EncodeLocalName(name);
source.CreateAttribute(null, name, namespaceUri, "");
source.MoveToAttribute(name, namespaceUri ?? "");
return source;
}
示例8: MakeNil
public bool MakeNil(XPathNavigator source)
{
if (source.NodeType == XPathNodeType.Element && IsNil(source) == false)
{
if (source.LookupPrefix(Xsi) != "xsi")
CreateNamespace("xsi", Xsi, source);
source.CreateAttribute("xsi", "nil", Xsi, "true");
return true;
}
return false;
}
示例9: CreateAttribute
public XPathNavigator CreateAttribute(string name, string namespaceUri, XPathNavigator source)
{
string prefix;
name = XmlConvert.EncodeLocalName(name);
if (IsRootNamespace(namespaceUri, out prefix))
prefix = CreateNamespace(prefix, namespaceUri, source);
source.CreateAttribute(prefix, name, namespaceUri, "");
source.MoveToAttribute(name, namespaceUri ?? "");
return source;
}
示例10: SetXmlStringAttributeValue
public static bool SetXmlStringAttributeValue(XPathNavigator parentNode, string valueName, string newValue)
{
if (parentNode == null || string.IsNullOrEmpty(valueName))
{
return false;
}
try
{
XPathNavigator factory = parentNode.Clone();
do
{
factory.MoveToFirstAttribute();
if (string.Compare(factory.Name, valueName) == 0)
{
factory.SetValue(newValue);
return true;
}
}
while (!factory.MoveToNextAttribute());
parentNode.CreateAttribute(string.Empty,
valueName,
string.Empty,
newValue);
return true;
}
catch (ArgumentNullException)
{
}
catch (InvalidOperationException)
{
}
return false;
}