當前位置: 首頁>>代碼示例>>C#>>正文


C# XPathNavigator.TryGetAttribute方法代碼示例

本文整理匯總了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;
        }
開發者ID:jasonhuber,項目名稱:SDataUpdateNestedEntities,代碼行數:52,代碼來源:SDataPayload.cs

示例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));
        }
開發者ID:jasonhuber,項目名稱:SDataUpdateNestedEntities,代碼行數:26,代碼來源:SDataPayload.cs

示例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;
        }
開發者ID:RyanFarley,項目名稱:SDataCSharpClientLib,代碼行數:46,代碼來源:SDataPayload.cs


注:本文中的System.Xml.XPath.XPathNavigator.TryGetAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。