本文整理汇总了C#中System.Xml.XPath.XPathNavigator.HasAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.HasAttribute方法的具体用法?C# XPathNavigator.HasAttribute怎么用?C# XPathNavigator.HasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.HasAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InferItemType
internal static ItemType InferItemType(XPathNavigator item)
{
string value;
if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out value) && XmlConvert.ToBoolean(value))
{
return ItemType.Property;
}
if (item.HasAttribute("key", Framework.Common.SData.Namespace) ||
item.HasAttribute("uuid", Framework.Common.SData.Namespace) ||
item.HasAttribute("lookup", Framework.Common.SData.Namespace) ||
item.HasAttribute("descriptor", Framework.Common.SData.Namespace))
{
return ItemType.Object;
}
if (item.HasAttribute("url", Framework.Common.SData.Namespace) ||
item.HasAttribute("uri", Framework.Common.SData.Namespace) ||
item.HasAttribute("deleteMissing", Framework.Common.SData.Namespace))
{
return ItemType.PayloadCollection;
}
if (item.IsEmptyElement)
{
// workaround: Older versions of the SIF generate payload collections as empty namespace-less elements
return string.IsNullOrEmpty(item.NamespaceURI) ? ItemType.PayloadCollection : ItemType.Property;
}
var children = item.SelectChildren(XPathNodeType.Element).Cast<XPathNavigator>();
var childCount = children.Count();
if (childCount == 0)
{
return ItemType.Property;
}
if (childCount > 1 && children.Select(child => child.LocalName).Distinct().Count() == 1)
{
if (children.All(child => InferItemType(child) == ItemType.Object))
{
return ItemType.PayloadCollection;
}
if (children.All(child => InferItemType(child) == ItemType.Property))
{
return ItemType.SimpleCollection;
}
}
return ItemType.Object;
}
示例2: InferItemType
internal static ItemType InferItemType(XPathNavigator item)
{
string value;
if (item.TryGetAttribute("nil", Framework.Common.XSI.Namespace, out value) && XmlConvert.ToBoolean(value))
{
return ItemType.Property;
}
if (item.HasAttribute("key", Framework.Common.SData.Namespace) ||
item.HasAttribute("uuid", Framework.Common.SData.Namespace) ||
item.HasAttribute("lookup", Framework.Common.SData.Namespace) ||
item.HasAttribute("descriptor", Framework.Common.SData.Namespace))
{
return ItemType.Object;
}
if (item.HasAttribute("url", Framework.Common.SData.Namespace) ||
item.HasAttribute("deleteMissing", Framework.Common.SData.Namespace) ||
item.IsEmptyElement)
{
return ItemType.PayloadCollection;
}
var children = item.SelectChildren(XPathNodeType.Element).Cast<XPathNavigator>();
var childCount = children.Count();
if (childCount == 0)
{
return ItemType.Property;
}
if (children.Select(child => child.LocalName).Distinct().Count() == 1 &&
children.All(child => InferItemType(child) == ItemType.Object))
{
return ItemType.PayloadCollection;
}
if (children.Select(child => child.LocalName).Distinct().Count() == 1 &&
children.All(child => InferItemType(child) == ItemType.Property))
{
return ItemType.SimpleCollection;
}
return ItemType.Object;
}