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


C# XPathNavigator.SelectAncestors方法代码示例

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


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

示例1: AddSchemaElement

 private void AddSchemaElement(XPathNavigator nav, XPathNavigator rootNav)
 {
     List<string> list = new List<string>();
     XPathNodeIterator iterator = nav.SelectAncestors(XPathNodeType.Element, true);
     while (iterator.MoveNext())
     {
         list.Add(iterator.Current.Name);
         if (iterator.Current.IsSamePosition(rootNav))
         {
             break;
         }
     }
     list.Reverse();
     OrderedDictionary first = this._rootSchema;
     Pair pair = null;
     foreach (string str in list)
     {
         pair = first[str] as Pair;
         if (pair == null)
         {
             pair = new Pair(new OrderedDictionary(), new ArrayList());
             first.Add(str, pair);
         }
         first = (OrderedDictionary) pair.First;
     }
     this.AddAttributeList(nav, (ArrayList) pair.Second);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:27,代码来源:XmlDocumentSchema.cs

示例2: NodeInfo

            public NodeInfo(XPathNavigator current)
            {
                List<string> xpathParts = new List<string>();
                XPathNodeIterator selection = current.SelectAncestors(XPathNodeType.All, true);

                while (selection.MoveNext())
                {
                    if (selection.Current.NodeType == XPathNodeType.Root)
                        break;

                    var node = selection.Current;
                    var name = node.Name;

                    if (!string.IsNullOrEmpty(node.NamespaceURI))
                    {
                        string prefix = this.GetPrefix(node);
                        name = string.Concat(prefix, ":", node.LocalName);
                    }

                    xpathParts.Add(
                        node.NodeType == XPathNodeType.Attribute
                            ? string.Format(AttributeXPath, name)
                            : string.Format(ElementXPath, name, this.GetNodeIndex(node)));

                    this.Root = node;
                }

                xpathParts.Reverse();

                this.XPath = string.Join("/", xpathParts);
            }
开发者ID:igorfrance,项目名称:sage,代码行数:31,代码来源:Set.cs

示例3: WriteElement

		static void WriteElement( StreamWriter writer, int indent, XPathNavigator element ) {
			string elementPrefix = new string( ' ', indent * 2 );
			string attributePrefix = new string( ' ', indent * 2 + 2 );

			writer.Write( "{0}<{1}", elementPrefix, element.Name );

			foreach ( XPathNavigator attribute in element.Select( "@*" ) ) {
				if ( element.Name == "VisualStudioProject" && attribute.Name == "Version" ) {
					writer.Write( "{0}{1}Version=\"8.00\"", Environment.NewLine, attributePrefix );
				}
				else if ( element.Name == "VisualStudioProject" && attribute.Name == "TargetFrameworkVersion" ) {
					// No op.
				}
				else if ( element.Name == "AssemblyReference" && attribute.Name == "MinFrameworkVersion" ) {
					// No op.
				}
				else if ( element.Name == "ProjectReference" && attribute.Name == "Include" ) {
					string newValue = Path.GetFileNameWithoutExtension( attribute.Value );
					newValue += ".2005" + Path.GetExtension( attribute.Value );
					writer.Write( " Include=\"{0}\"", newValue );
				}
				else if ( element.Name == "Import" && attribute.Name == "Project" ) {
					string newValue = attribute.Value.Replace( "$(MSBuildToolsPath)", "$(MSBuildBinPath)" );
					writer.Write( " Project=\"{0}\"", newValue );
				}
				else {
					writer.Write( "{0}{1}{2}=\"{3}\"", Environment.NewLine, attributePrefix, attribute.Name, attribute.Value );
				}
			}

			if ( element.Name == "Project" )
			{
				XPathNodeIterator ancestors = element.SelectAncestors(XPathNodeType.Element, false);
				if ( ancestors.Count == 0 )
					writer.Write( Environment.NewLine + "  xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"" );
			}

			if ( element.HasChildren ) {
				writer.Write( ">" );

				bool writeNewline = true;
				foreach ( XPathNavigator child in element.SelectChildren( XPathNodeType.Element ) ) {
					if ( writeNewline )
					{
						writer.WriteLine();
						writeNewline = false;
					}

					WriteElement( writer, indent + 1, child );
				}

				foreach ( XPathNavigator child in element.SelectChildren( XPathNodeType.Text ) ) {
					writer.Write( child.Value );
				}

				if ( !writeNewline )
				{
					writer.Write(elementPrefix);
				}

				writer.WriteLine( "</{0}>", element.Name );
			}
			else {
				writer.WriteLine( "/>" );
			}
		}
开发者ID:zhandb,项目名称:slimdx,代码行数:66,代码来源:DowngradeProject.cs

示例4: CheckOr

        private bool CheckOr(XPathNavigator rowNavigator)
        {
            if (orIDs.Count == 0)
            {
                return true;
            }

            bool check = false;

            XPathNodeIterator ancestors = rowNavigator.SelectAncestors(XPathNodeType.Element, true);

            foreach (XPathNavigator ancestor in ancestors)
            {
                String ancestorIDString = ancestor.GetAttribute(idAttribute, ancestor.NamespaceURI);

                if (ancestor.Name.Equals("TimelineRow") && ancestorIDString != null && ancestorIDString.Length > 0)
                {
                    int intID = Int32.Parse(ancestorIDString);

                    if (orIDs.Contains(intID))
                    {
                        check = true;
                    }
                }
            }

            XPathNodeIterator descendants = rowNavigator.Select(".//TimelineRow | .//TimelineFilter");
            foreach (XPathNavigator descendant in descendants)
            {
                String descendantIDString = descendant.GetAttribute(idAttribute, descendant.NamespaceURI);

                if (descendantIDString != null && descendantIDString.Length > 0)
                {
                    int intID = Int32.Parse(descendantIDString);

                    if (orIDs.Contains(intID))
                    {
                        check = true;
                    }
                }
            }
            
            return check;
        }
开发者ID:wshanshan,项目名称:DDD,代码行数:44,代码来源:Timeline.cs

示例5: CreateLocation

        private string CreateLocation(XPathNavigator context)
        {
            Stack<string> steps = new Stack<string>();

            if (context.NodeType == XPathNodeType.Attribute)
            {
                steps.Push(String.Format("@{0}", context.Name));
            }
            else if (context.NodeType == XPathNodeType.Text)
            {
                steps.Push("text()");
            }

            XPathNodeIterator ancestors = context.SelectAncestors(XPathNodeType.Element, true);
            while (ancestors.MoveNext())
            {
                XPathNavigator current = ancestors.Current;
                if (current.NodeType == XPathNodeType.Element)
                {
                    // resolve namespace
                    XmlNamespaceManager nsManager = new XmlNamespaceManager(new NameTable());
                    nsManager.AddNamespace(current.Prefix, current.NamespaceURI);

                    // resolve name + position
                    string name = current.Name;
                    int position = 1 + ancestors.Current.Select(String.Format("preceding-sibling::{0}", name), nsManager).Count;
                    steps.Push(String.Format("{0}[{1}]", name, position));
                }
            }

            // results
            StringBuilder sb = new StringBuilder();
            while (steps.Count > 0)
            {
                sb.Append("/");
                sb.Append(steps.Pop());
            }

            return sb.ToString();
        }
开发者ID:xpekatt,项目名称:SchemaTron,代码行数:40,代码来源:ValidationEvaluator.cs


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