当前位置: 首页>>代码示例>>C#>>正文


C# XElement.GetNamespaceOfPrefix方法代码示例

本文整理汇总了C#中System.Xml.Linq.XElement.GetNamespaceOfPrefix方法的典型用法代码示例。如果您正苦于以下问题:C# XElement.GetNamespaceOfPrefix方法的具体用法?C# XElement.GetNamespaceOfPrefix怎么用?C# XElement.GetNamespaceOfPrefix使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Xml.Linq.XElement的用法示例。


在下文中一共展示了XElement.GetNamespaceOfPrefix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetXName

 public XName GetXName(XElement elem, string reference)
 {
     string[] parts = reference.Split(':');
     if (parts.Length == 2)
     {
         XNamespace ns = elem.GetNamespaceOfPrefix(parts[0]);
         if (ns != null)
         {
             return ns + parts[1];
         }
         else
         {
             this.Importer.Diagnostics.AddError("Invalid namespace prefix: " + parts[0], this.Uri, this.GetTextSpan(elem));
             return null;
         }
     }
     else if (parts.Length == 1)
     {
         XNamespace ns = elem.GetDefaultNamespace();
         return ns + parts[0];
     }
     else
     {
         return null;
     }
 }
开发者ID:Bubesz,项目名称:soal-cs,代码行数:26,代码来源:XmlReader.cs

示例2: ResolveNamespace

		public void ResolveNamespace(XElement elem, XamlContext ctx) {
			if (Namespace != null)
				return;

			// Since XmlnsProperty records are inside the element,
			// the namespace is resolved after processing the element body.

			string xmlNs = null;
			if (elem.Annotation<XmlnsScope>() != null)
				xmlNs = elem.Annotation<XmlnsScope>().LookupXmlns(Assembly, TypeNamespace);
			if (xmlNs == null)
				xmlNs = ctx.XmlNs.LookupXmlns(Assembly, TypeNamespace);

			if (xmlNs == null) {
				var nsSeg = TypeNamespace.Split('.');
				var nsName = nsSeg[nsSeg.Length - 1].ToLowerInvariant();
				var prefix = nsName;
				int count = 0;
				while (elem.GetNamespaceOfPrefix(prefix) != null) {
					count++;
					prefix = nsName + count;
				}

				xmlNs = string.Format("clr-namespace:{0};assembly={1}", TypeNamespace, Assembly);
				elem.Add(new XAttribute(XNamespace.Xmlns + XmlConvert.EncodeLocalName(prefix),
					ctx.GetXmlNamespace(xmlNs)));
			}
			Namespace = xmlNs;
		}
开发者ID:arkanoid1,项目名称:dnSpy,代码行数:29,代码来源:XamlType.cs

示例3: Initialize

 public void Initialize(XElement element)
 {
     this.initializedAttributes = this.Attributes
         .Select(_ => new AttributeSelector(
             _.Name, 
             (element.GetNamespaceOfPrefix(_.Namespace)?.NamespaceName ?? _.Namespace),
             _.Value))
         .ToList();
 }
开发者ID:tmatz,项目名称:XamlStyler,代码行数:9,代码来源:AttributeRemovalService.cs

示例4: Write

        public static void Write(XElement container, KeyValuePair<string, object> kvp)
        {
            var element = new XElement(container.GetNamespaceOfPrefix("d") + kvp.Key);;

            if (kvp.Value == null)
            {
                element.SetAttributeValue(container.GetNamespaceOfPrefix("m") + "null", "true");
            }
            else
            {
                var type = EdmType.FromSystemType(kvp.Value.GetType());
                if (type != EdmType.String)
                {
                    element.SetAttributeValue(container.GetNamespaceOfPrefix("m") + "type", type.ToString());
                }
                element.SetValue(Writers[type](kvp.Value));
            }

            container.Add(element);
        }
开发者ID:christianblunden,项目名称:Simple.Data,代码行数:20,代码来源:EdmHelper.cs

示例5: LookupNamespace

 public static Func<string, string> LookupNamespace(XElement element)
 {
     return prefix =>
                {
                    var ns = element.GetNamespaceOfPrefix(prefix);
                    if (ns == null)
                    {
                        return null;
                    }
                    return ns.NamespaceName;
                };
 }
开发者ID:iansrobinson,项目名称:Restbucks,代码行数:12,代码来源:LinksAssembler.cs

示例6: Parse

        public static YouTubeChannelVideo Parse(XElement xItem)
        {
            // Get namespaces
            XNamespace atom = xItem.GetNamespaceOfPrefix("atom");
            XNamespace media = xItem.GetNamespaceOfPrefix("media");
            XNamespace yt = xItem.GetNamespaceOfPrefix("yt");

            // Some pre-parsing
            XElement xMedia = xItem.Element(media + "group");
            XElement xDuration = xMedia.Element(yt + "duration");

            // Initialize and return the object
            return new YouTubeChannelVideo {
                Id = Regex.Match(xItem.GetElementValue("link"), "v=([v-]{11})").Groups[1].Value,
                Published = xItem.GetElementValue<DateTime>("pubDate"),
                LastUpdated = xItem.GetElementValue<DateTime>(atom + "updated"),
                Title = xItem.GetElementValue("title"),
                Description = xMedia.GetElementValue(media + "description"),
                Link = xItem.GetElementValue("link"),
                Author = xItem.GetElementValue("author"),
                Duration = xDuration.GetAttributeValue<int>("seconds")
            };
        }
开发者ID:Jeavon,项目名称:UmbracoExtensionMethods,代码行数:23,代码来源:YouTubeChannelVideo.cs

示例7: ResolveNamespace

		public void ResolveNamespace(XElement elem, XamlContext ctx) {
			if (Namespace != null)
				return;

			// Since XmlnsProperty records are inside the element,
			// the namespace is resolved after processing the element body.

			string xmlNs = null;
			if (elem.Annotation<XmlnsScope>() != null)
				xmlNs = elem.Annotation<XmlnsScope>().LookupXmlns(Assembly, TypeNamespace);
			if (xmlNs == null)
				xmlNs = ctx.XmlNs.LookupXmlns(Assembly, TypeNamespace);
			// Sometimes there's no reference to System.Xaml even if x:Type is used
			if (xmlNs == null)
				xmlNs = ctx.TryGetXmlNamespace(Assembly, TypeNamespace);

			if (xmlNs == null) {
				if (AssemblyNameComparer.CompareAll.Equals(Assembly, ctx.Module.Assembly))
					xmlNs = $"clr-namespace:{TypeNamespace}";
				else
					xmlNs = $"clr-namespace:{TypeNamespace};assembly={Assembly.Name}";

				var nsSeg = TypeNamespace.Split('.');	
				var prefix = nsSeg[nsSeg.Length - 1].ToLowerInvariant();
				if (string.IsNullOrEmpty(prefix)) {
					if (string.IsNullOrEmpty(TypeNamespace))
						prefix = "global";
					else
						prefix = "empty";
				}
				int count = 0;
				var truePrefix = prefix;
				XNamespace prefixNs, ns = ctx.GetXmlNamespace(xmlNs);
				while ((prefixNs = elem.GetNamespaceOfPrefix(truePrefix)) != null && prefixNs != ns) {
					count++;
					truePrefix = prefix + count;
				}

				if (prefixNs == null) {
					elem.Add(new XAttribute(XNamespace.Xmlns + XmlConvert.EncodeLocalName(truePrefix), ns));
					if (string.IsNullOrEmpty(TypeNamespace))
						elem.AddBeforeSelf(new XComment(string.Format(dnSpy_BamlDecompiler_Resources.Msg_GlobalNamespace, truePrefix)));
				}
			}
			Namespace = ctx.GetXmlNamespace(xmlNs);
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:46,代码来源:XamlType.cs

示例8: DeserializeXElement

 private object DeserializeXElement(XElement e, object obj, Type defaultType, SerializationScope typeScope)
 {
     Debug.Assert(e != null && defaultType != null);
     // 对于集合,从元素名推理对象类型。
     var xsiTypeName = (string)e.Attribute(XsiType);
     Type objType;
     if (xsiTypeName == null)
     {
         //未指定 xsi:type,则使用 defaultType
         objType = defaultType;
     }
     else
     {
         //指定了 xsi:type
         //解析 prefix:localName
         var parts = xsiTypeName.Split(':');
         XName xName;
         if (parts.Length <= 1) xName = e.GetDefaultNamespace() + xsiTypeName;
         else xName = e.GetNamespaceOfPrefix(parts[0]) + parts[1];
         objType = _Builder.GlobalScope.GetType(xName);
         if (objType == null)
             throw new NotSupportedException(string.Format(Prompts.UnregisteredType, xsiTypeName, typeScope));
     }
     var s = _Builder.GetSerializer(objType);
     if (s == null)
         throw new NotSupportedException(string.Format(Prompts.UnregisteredType, objType, typeScope));
     return s.Deserialize(e, obj, this, typeScope);
 }
开发者ID:CXuesong,项目名称:XSerializer,代码行数:28,代码来源:XSerializationState.cs

示例9: ParseCseResult

 private GoogleSearchResult ParseCseResult(XElement searchResult)
 {
     var nsCse = searchResult.GetNamespaceOfPrefix("cse");
     var nsAtom = searchResult.GetDefaultNamespace();
     var tmpResult = new GoogleSearchResult();
     var title = searchResult.Element(nsAtom + "title");
     if (title != null) tmpResult.Title = title.Value;
     var link = searchResult.Element(nsAtom + "link");
     if (link != null)
     {
         if (link.Attribute("href") != null)
         {
             tmpResult.Url = link.Attribute("href").Value;
         }
     }
     var description = searchResult.Element(nsAtom + "summary");
     if (description != null)
     {
         tmpResult.Description = description.Value;
     }
     var mime = searchResult.Element(nsCse + "mime");
     if (mime != null)
     {
         tmpResult.Mime = mime.Value;
     }
     return tmpResult;
 }
开发者ID:kai33,项目名称:DotNet-Google-CSE-API,代码行数:27,代码来源:GoogleSearch.cs

示例10: GetXmlNameFromString

        internal static XName GetXmlNameFromString(string value, XElement parent)
        {
            Debug.Assert(parent!=null);
            if (parent==null)
                throw new ArgumentNullException("parent");

            string[] ne=value.Split(new char[] { ':' }, 2);
            string name=ne[0];
            if (ne.Length>1)
            {
                name=ne[1];
                XNamespace @namespace=parent.GetNamespaceOfPrefix(ne[0]);
                if (@namespace==null)
                    throw new XmlException(
                        string.Format(
                            CultureInfo.CurrentCulture,
                            SR.CouldNotFindNamespaceFromPrefix,
                            ne[0]
                        )
                    );

                return XName.Get(name, @namespace.NamespaceName);
            }

            return XName.Get(name);
        }
开发者ID:mcartoixa,项目名称:GeoSIK,代码行数:26,代码来源:Discovery.cs

示例11: ResolvePrefix

 private static XNamespace ResolvePrefix(XElement element, string prefix)
 {
     return string.IsNullOrEmpty(prefix) ? element.GetDefaultNamespace() : element.GetNamespaceOfPrefix(prefix);
 }
开发者ID:christianblunden,项目名称:Simple.Data,代码行数:4,代码来源:XElementExtensions.cs

示例12: TrySearchObject

        private StoreItem TrySearchObject(StoreItemType objType, string nameWithPrefix, XElement def)
        {
            if (nameWithPrefix == null) return null;
            if (!nameWithPrefix.Contains(":")) return null;
            string prefix = (string)nameWithPrefix.Split(char.Parse(":")).GetValue(0);
            XNamespace objNS = def.GetNamespaceOfPrefix(prefix);

            string name = (string)nameWithPrefix.Split(char.Parse(":")).GetValue(1);

            var objs = from c in store
                       where c.objectType == objType &&
                             c.name == name &&
                             c.ownNS == objNS
                       select c;

            if (objs.Count<StoreItem>() != 1)
            {
                return null;
            }
            else
            {
                return objs.First<StoreItem>();
            }
        }
开发者ID:st9200,项目名称:soal-oslo,代码行数:24,代码来源:XsdWsdlRefactor.cs

示例13: ParseItem

        private static YouTubeVideo ParseItem(XElement xItem)
        {
            // Get namespaces
            XNamespace atom = xItem.GetNamespaceOfPrefix("atom");
            XNamespace media = xItem.GetNamespaceOfPrefix("media");
            XNamespace yt = xItem.GetNamespaceOfPrefix("yt");
            XNamespace gd = xItem.GetNamespaceOfPrefix("gd");

            // Some pre-parsing
            XElement xMedia = xItem.Element(media + "group");
            XElement xDuration = xMedia.Element(yt + "duration");

            // Get the <yt:statistics> element describing the number of favorites and
            // number of views
            XElement xStatistics = xItem.Element(yt + "statistics");

            // Get the <yt:rating> element describing the number of lines and
            // number of dislikes (may not always be present)
            XElement xYouTubeRating = xItem.Element(yt + "rating");

            // Get the <gd:rating> element describing the video rating and
            // number of raters
            XElement xGoogleRating = xItem.Element(gd + "rating");

            // Initialize and return the object
            YouTubeVideo video = new YouTubeVideo();
            video.Id = GetVideoId(xItem);
            video.Published = xItem.GetElementValue<DateTime>("pubDate");
            video.LastUpdated = xItem.GetElementValue<DateTime>(atom + "updated");
            video.Title = xItem.GetElementValue("title");
            video.Description = xItem.GetElementValue("description");
            video.Link = xItem.GetElementValue("link");
            video.Author = xItem.GetElementValue("author");
            video.Duration = TimeSpan.FromSeconds(xDuration.GetAttributeValue<int>("seconds"));
            video.FavoriteCount = xStatistics == null ? 0 : xStatistics.GetAttributeValue<int>("favoriteCount");
            video.ViewCount = xStatistics == null ? 0 : xStatistics.GetAttributeValue<int>("viewCount");
            video.Likes = xYouTubeRating == null ? 0 : xYouTubeRating.GetAttributeValue<int>("numLikes");
            video.Dislikes = xYouTubeRating == null ? 0 : xYouTubeRating.GetAttributeValue<int>("numDislikes");
            video.Rating = xGoogleRating == null ? 0 : xGoogleRating.GetAttributeValue<int>("average");
            video.NumberOfRaters = xGoogleRating == null ? 0 : xGoogleRating.GetAttributeValue<int>("numRaters");
            return video;
        }
开发者ID:Jeavon,项目名称:UmbracoExtensionMethods,代码行数:42,代码来源:YouTubeVideo.cs

示例14: SearchObject

        private Collective SearchObject(ObjectTypes objType, string nameWithPrefix, XElement def)
        {
            // TODO: !!! MI VAN, HA NINCS PREFIX ???
            string prefix = (string)nameWithPrefix.Split(char.Parse(":")).GetValue(0);
            XNamespace objNS = def.GetNamespaceOfPrefix(prefix);

            string name = (string)nameWithPrefix.Split(char.Parse(":")).GetValue(1);

            var objs = from c in readedElements
                       where c.objectType == objType &&
                             c.name == name &&
                             c.ownNS == objNS
                       select c;

            if (objs.Count<Collective>() != 1)
            {
                Wr("Searched Object not found: " + nameWithPrefix);
                throw new Exception();
            }
            else
            {
                return objs.First<Collective>();
            }
        }
开发者ID:st9200,项目名称:soal-oslo,代码行数:24,代码来源:XsdWsdlRefactor0.cs

示例15: ElementGetNamespaceOfPrefix

        public void ElementGetNamespaceOfPrefix()
        {
            XNamespace ns = XNamespace.Get("http://test");
            XElement e = new XElement(ns + "foo");

            Assert.Throws<ArgumentNullException>(() => e.GetNamespaceOfPrefix(null));
            Assert.Throws<ArgumentException>(() => e.GetNamespaceOfPrefix(string.Empty));

            XNamespace n = e.GetNamespaceOfPrefix("xmlns");
            Assert.Equal("http://www.w3.org/2000/xmlns/", n.NamespaceName);

            n = e.GetNamespaceOfPrefix("xml");
            Assert.Equal("http://www.w3.org/XML/1998/namespace", n.NamespaceName);

            n = e.GetNamespaceOfPrefix("myns");
            Assert.Null(n);

            XDocument doc = new XDocument(e);
            e.SetAttributeValue("{http://www.w3.org/2000/xmlns/}myns", ns);
            n = e.GetNamespaceOfPrefix("myns");
            Assert.NotNull(n);
            Assert.Equal(ns, n);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:23,代码来源:SDMElement.cs


注:本文中的System.Xml.Linq.XElement.GetNamespaceOfPrefix方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。