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


C# XmlDocument.CreateNavigator方法代码示例

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


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

示例1: List1

		public void List1()
		{
			string xml = @"<?xml version='1.0'?>
<root>
	<element>1</element>
	<element></element>
	<element/>
	<element>2</element>
</root>";

			XmlDocument doc = new XmlDocument();
			doc.LoadXml(xml);

			XPathNodeIterator iterator = doc.CreateNavigator().Select("//element");
			XmlNodeList list = XmlNodeListFactory.CreateNodeList(iterator);

			int count = 0;
			foreach (XmlNode n in list)
			{
				count++;
			}
			Assert.AreEqual(4, count);

			iterator = doc.CreateNavigator().Select("//element");
			list = XmlNodeListFactory.CreateNodeList(iterator);
			Assert.AreEqual(4, list.Count);
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:27,代码来源:XmlNodeListFactoryTests.cs

示例2: Apply

        public void Apply (XmlDocument targetDocument, IXmlNamespaceResolver context) {

            XPathExpression local_file_expression = file_expression.Clone();
            local_file_expression.SetContext(context);

            XPathExpression local_source_expression = source_expression.Clone();
            local_source_expression.SetContext(context);

            XPathExpression local_target_expression = target_expression.Clone();
            local_target_expression.SetContext(context);

            string file_name = (string) targetDocument.CreateNavigator().Evaluate(local_file_expression);
            string file_path = Path.Combine(root_directory, file_name);

            if (!File.Exists(file_path)) return;
            XPathDocument sourceDocument = new XPathDocument(file_path);

            XPathNavigator target_node = targetDocument.CreateNavigator().SelectSingleNode(local_target_expression);
            if (target_node == null) return;

            XPathNodeIterator source_nodes = sourceDocument.CreateNavigator().Select(local_source_expression);
            foreach (XPathNavigator source_node in source_nodes) {
                target_node.AppendChild(source_node);
            }
       
        }
开发者ID:Balamir,项目名称:DotNetOpenAuth,代码行数:26,代码来源:CopyFromFiles.cs

示例3: EqualNavigators

		public void EqualNavigators()
		{
			XmlDocument doc = new XmlDocument();
			doc.LoadXml( @"
				<root xmlns:u='uuu'>
					<u:element1 attr1='1' attr2='b'>
						<subelement1>uhus</subelement1>
						<!-- uhus was here -->
					</u:element1>
				</root>
				<!-- and here -->
			" );

			NavigatorUtils.AreEqual( doc.CreateNavigator(), doc.CreateNavigator() );
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:15,代码来源:NavigatorUtilsTest.cs

示例4: load

 private void load(string config_file)
 {
     XmlDocument document = new XmlDocument();
       try
       {
     document.Load(config_file);
     XPathNavigator navigator = document.CreateNavigator();
     XPathNodeIterator iterator = (XPathNodeIterator)
       navigator.Evaluate("config/*");
     while (iterator.MoveNext())
     {
       XPathNavigator element = iterator.Current;
       switch (element.Name)
       {
     case "src2srcml-path":
       src2srcml_path = element.Value;
       break;
       }
     }
       }
       catch (Exception e)
       {
     throw e;
       }
 }
开发者ID:jmeinken,项目名称:itrace-pilot,代码行数:25,代码来源:Config.cs

示例5: XmlDocument

        /// <exception cref="BetOMaticException"/>
        XmlDocument IBetOMaticService.FindEvents(string[] keywords, int startIndex, int count, bool commentInfo)
        {
            XmlDocument xmlDocument = new XmlDocument();

            try
            {
                xmlDocument.Load(String.Format(betomaticFindEventsUri, String.Join("+", keywords), startIndex, count));

                if (commentInfo)
                {
                    /* Add the number of comments to each event */
                    XPathNavigator navigator = xmlDocument.CreateNavigator();
                    XPathNodeIterator iterator = navigator.Select("//event");
                    while (iterator.MoveNext())
                    {
                        XPathNodeIterator itId = iterator.Current.Select("./id");
                        itId.MoveNext();
                        int numberOfComments = CommentDao.GetNumberOfCommentsByEvent(int.Parse(itId.Current.InnerXml));
                        iterator.Current.AppendChildElement("", "numberOfComments", "", numberOfComments.ToString());
                    }
                }
            }
            catch (FileNotFoundException)
            {
                throw new BetOMaticException();
            }
            catch (WebException)
            {
                throw new BetOMaticException();
            }

            return xmlDocument;
        }
开发者ID:fpozzas,项目名称:fic,代码行数:34,代码来源:BetOMaticService.cs

示例6: op_Evaluate_XPathNavigator_stringNull

        public void op_Evaluate_XPathNavigator_stringNull()
        {
            var xml = new XmlDocument();
            xml.LoadXml("<foo>bar</foo>");

            Assert.Throws<ArgumentNullException>(() => xml.CreateNavigator().Evaluate<string>(null));
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:XPathNavigator.ExtensionMethods.Facts.cs

示例7: op_Evaluate_XPathNavigator_string

        public void op_Evaluate_XPathNavigator_string()
        {
            var xml = new XmlDocument();
            xml.LoadXml("<foo>bar</foo>");

            Assert.True(xml.CreateNavigator().Evaluate<bool>("1=count(/foo[text()='bar'])"));
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:7,代码来源:XPathNavigator.ExtensionMethods.Facts.cs

示例8: tokenize

		/// <summary>
		/// Implements the following function 
		///		node-set tokenize(string, string)
		/// </summary>
		/// <param name="str"></param>
		/// <param name="delimiters"></param>				
		/// <returns>This function breaks the input string into a sequence of strings, 
		/// treating any character in the list of delimiters as a separator. 
		/// The separators themselves are not returned. 
		/// The tokens are returned as a set of 'token' elements.</returns>
		public XPathNodeIterator tokenize(string str, string delimiters)
		{

			XmlDocument doc = new XmlDocument();
			doc.LoadXml("<tokens/>");

			if (delimiters == String.Empty)
			{
				foreach (char c in str)
				{
					XmlElement elem = doc.CreateElement("token");
					elem.InnerText = c.ToString();
					doc.DocumentElement.AppendChild(elem);
				}
			}
			else
			{
				foreach (string token in str.Split(delimiters.ToCharArray()))
				{

					XmlElement elem = doc.CreateElement("token");
					elem.InnerText = token;
					doc.DocumentElement.AppendChild(elem);
				}
			}

			return doc.CreateNavigator().Select("//token");
		}
开发者ID:zanyants,项目名称:mvp.xml,代码行数:38,代码来源:ExsltStrings.cs

示例9: News

 /// <summary>
 /// Initializes a new instance of the <see cref="News"/> class.
 /// </summary>
 /// <param name="RssFeedTransformer">The RSS feed transformer.</param>
 /// <remarks>Documented by Dev02, 2007-11-28</remarks>
 public News(string RssFeedTransformer)
 {
     XmlDocument rssFeedTransformer = new XmlDocument();
     XsltSettings settings = new XsltSettings(false, true);     //disable scripts and enable document()
     rssFeedTransformer.LoadXml(RssFeedTransformer);
     xslTransformer.Load(rssFeedTransformer.CreateNavigator(), settings, new XmlUrlResolver());
 }
开发者ID:Stoner19,项目名称:Memory-Lifter,代码行数:12,代码来源:News.cs

示例10: GetDataSummary

        protected virtual string GetDataSummary(Stream xsltStream)
        {
            DataSet data = this.GetDataSet;
            if (xsltStream == null || data == null)
                return null;

            Stream dsStream = new MemoryStream();
            data.WriteXml(dsStream);

            TextWriter tw = new StringWriter();

            try
            {
                XslTransform xsl = new XslTransform();

                XmlDocument XSLTDoc = new XmlDocument();
                XSLTDoc.Load(xsltStream);
                XmlDocument dataDoc = new XmlDocument();
                dataDoc.LoadXml(data.GetXml());

                XPathNavigator stylesheet = XSLTDoc.CreateNavigator();
                xsl.Load(stylesheet, null, null);
                XPathNavigator dataNav = dataDoc.CreateNavigator();

                xsl.Transform(dataNav, null, tw, null);
            }
            catch (Exception ex)
            {
                return null;
            }

            return tw.ToString();
        }
开发者ID:mbmccormick,项目名称:Ximura,代码行数:33,代码来源:DataContent_IDataContentSummary.cs

示例11: OpenReader

 public override XmlReader OpenReader()
 {
     // NOTE: Renders in memory. Most objects will already be in memory and therefore small but some implementations might be large.
     XmlDocumentFragment frag = new XmlDocument().CreateDocumentFragment();
     _obj.WriteXml(frag.CreateNavigator().AppendChild());
     return new XmlNodeReader(frag);
 }
开发者ID:bittercoder,项目名称:Lob,代码行数:7,代码来源:XmlSerializableObjectXlob.cs

示例12: ReadXml

        public IResourceActions ReadXml(IXPathNavigable idoc)
        {
            // Basic check on the input
            if (idoc == null)
            {
				Logger.LogError("XmlResourceReader.ReadXml: null XmlDoc input");
                throw new ApplicationException(Properties.Resources.COULD_NOT_READ_RESOURCES);
            }

            XPathNavigator doc = idoc.CreateNavigator();
            XPathNavigator rootNode = doc.SelectSingleNode(@"PolicySetResources");
            if (rootNode == null)
            {
                XmlNode node = new XmlDocument().CreateElement("PolicySetResources");                
                rootNode = node.CreateNavigator();
                doc.AppendChild(rootNode);
            }

            // Check if the document contains an actions node
            XPathNavigator actionsNode = rootNode.SelectSingleNode(@"Actions");
            if (actionsNode == null)
            {
                // No actions already defined in the resources so nothing to read
                // Return an empty collection of resource actions
                return new ResourceActions();
            }

            return ReadActions(actionsNode);
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:29,代码来源:XmlResourceReader.cs

示例13: Apply

		// the work of the component

		public override void Apply (XmlDocument document, string key) {

			// adjust the context
			context["key"] = key;

			// evaluate the condition
			XPathExpression xpath_local = xpath.Clone();
			xpath_local.SetContext(context);
            
			Object result = document.CreateNavigator().Evaluate(xpath_local);
           
			// try to intrepret the result as a node set
			XPathNodeIterator result_node_iterator = result as XPathNodeIterator;

			if (result_node_iterator != null) {
                XPathNavigator[] result_nodes = BuildComponentUtilities.ConvertNodeIteratorToArray(result_node_iterator);
				//Console.WriteLine("{0} node-set result", result_nodes.Length);
				// if it is, apply the child components to each node value
				foreach (XPathNavigator result_node in result_nodes) {
                    // Console.WriteLine(result_node.Value);
					ApplyComponents(document, result_node.Value);
				}
			} else {
				//Console.WriteLine("non-node-set result");
				// if it isn't, apply the child components to the string value of the result
				ApplyComponents(document, result.ToString());

			}


		}
开发者ID:Balamir,项目名称:DotNetOpenAuth,代码行数:33,代码来源:ForEachComponent.cs

示例14: BindingRedirectResolverConfigDlg

        //=====================================================================
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="currentProject">The current project</param>
        /// <param name="currentConfig">The current XML configuration
        /// XML fragment</param>
        public BindingRedirectResolverConfigDlg(SandcastleProject currentProject,
          string currentConfig)
        {
            XPathNavigator navigator, root;

            InitializeComponent();
            project = currentProject;

            lnkCodePlexSHFB.Links[0].LinkData = "http://SHFB.CodePlex.com";

            items = new BindingRedirectSettingsCollection();

            // Load the current settings
            config = new XmlDocument();
            config.LoadXml(currentConfig);
            navigator = config.CreateNavigator();

            root = navigator.SelectSingleNode("configuration");

            if(!root.IsEmptyElement)
                items.FromXml(project, root);

            if(items.Count == 0)
                pgProps.Enabled = btnDelete.Enabled = false;
            else
            {
                // Binding the collection to the list box caused some
                // odd problems with the property grid so we'll add the
                // items to the list box directly.
                foreach(BindingRedirectSettings brs in items)
                    lbRedirects.Items.Add(brs);

                lbRedirects.SelectedIndex = 0;
            }
        }
开发者ID:codemonster234,项目名称:scbuilder,代码行数:42,代码来源:BindingRedirectResolverConfigDlg.cs

示例15: DiscoverMoveToFollowing

        public void DiscoverMoveToFollowing()
        {
            var doc = new XmlDocument();
            doc.LoadXml(@"<root><a id='1'><b>foo</b><c>bar</c></a><a id='2'/></root>");
            Assert.That(doc.InnerText.Length, Is.GreaterThan(5));
            var nav = doc.CreateNavigator();

            Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
            Assert.That( nav.Name, Is.EqualTo("root") );

            Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
            Assert.That( nav.Name, Is.EqualTo("a") );
            Assert.That( nav.GetAttribute("id",""), Is.EqualTo("1") );

            Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
            Assert.That( nav.Name, Is.EqualTo("b") );

            Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
            Assert.That( nav.Name, Is.EqualTo("c") );

            Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.True );
            Assert.That( nav.Name, Is.EqualTo("a") );
            Assert.That( nav.GetAttribute("id",""), Is.EqualTo("2") );

            Assert.That( nav.MoveToFollowing(XPathNodeType.Element), Is.False );
        }
开发者ID:Oaz,项目名称:XmlDocumentProcessor,代码行数:26,代码来源:SpikeXmlPathNavigator.cs


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