當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。