本文整理汇总了C#中System.Xml.XPath.XPathNavigator.TryGetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# XPathNavigator.TryGetAttribute方法的具体用法?C# XPathNavigator.TryGetAttribute怎么用?C# XPathNavigator.TryGetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XPath.XPathNavigator
的用法示例。
在下文中一共展示了XPathNavigator.TryGetAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: Load
public bool Load(XPathNavigator source, XmlNamespaceManager manager)
{
//------------------------------------------------------------
// Validate parameter
//------------------------------------------------------------
Guard.ArgumentNotNull(source, "source");
//------------------------------------------------------------
// Attempt to extract syndication information
//------------------------------------------------------------
ResourceName = source.LocalName;
Namespace = source.NamespaceURI;
string value;
Key = source.TryGetAttribute("key", Framework.Common.SData.Namespace, out value) ? value : null;
Uri = source.TryGetAttribute("uri", Framework.Common.SData.Namespace, out value) && !string.IsNullOrEmpty(value) ? new Uri(value) : null;
Uuid = source.TryGetAttribute("uuid", Framework.Common.SData.Namespace, out value) && !string.IsNullOrEmpty(value) ? new Guid(value) : (Guid?) null;
Descriptor = source.TryGetAttribute("descriptor", Framework.Common.SData.Namespace, out value) ? value : null;
Lookup = source.TryGetAttribute("lookup", Framework.Common.SData.Namespace, out value) ? value : null;
IsDeleted = source.TryGetAttribute("isDeleted", Framework.Common.SData.Namespace, out value) && !string.IsNullOrEmpty(value) ? XmlConvert.ToBoolean(value) : (bool?) null;
return source.SelectChildren(XPathNodeType.Element)
.Cast<XPathNavigator>()
.GroupBy(item => item.LocalName)
.All(group => LoadItem(group.Key, group, manager));
}
示例3: 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;
}