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


C# XmlDocument.SafeSelectNodes方法代码示例

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


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

示例1: ParseXmlDocument

        public List<INCoverNode> ParseXmlDocument(XmlDocument results, Regex partOfPathToKeep)
        {
            foreach (var node in results.SafeSelectNodes("//doc").Where(node => !XmlNodeHelper.GetBoolAttribute("excluded", node)))
            {
                documents[XmlNodeHelper.GetIntAttribute("id", node)] = XmlNodeHelper.GetStringAttribute("url", node);
            }

            return (results.SafeSelectNodes("//seqpnt").Select(node => ParseNode(node, partOfPathToKeep))).ToList();
        }
开发者ID:NigelThorne,项目名称:NCoverCop,代码行数:9,代码来源:NCoverXmlParserV2.cs

示例2: PrepareElementsOnPage_FromShell_MakesVernacularAndNationalEmpty

        public void PrepareElementsOnPage_FromShell_MakesVernacularAndNationalEmpty()
        {
            var contents = @"<div class='bloom-page numberedPage A5Portrait bloom-monolingual'
                            id='f4a22289-1755-4b79-afc1-5d20eaa892fe'>
            <div class='marginBox'>
              <div class='bloom-imageContainer'>
            <img alt='' src='test.png' height='20' width='20'/>
              </div>
              <div class='bloom-translationGroup normal-style'>
            <div style='' class='bloom-editable' contenteditable='true'
            lang='en'>The Mother said, Nurse!
            The Nurse answered.</div>
            <div style='' class='bloom-editable' contenteditable='true'
            lang='tpi'>Mama i tok: Sista.
            Sista i tok: Bai mi stori long yu.</div>
              </div>
            </div></div>";
            var dom = new XmlDocument();
            dom.LoadXml(contents);

            TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @contenteditable='true' ]", 5);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='en' and contains(., 'The Mother')]", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='tpi' and contains(., 'Mama i tok')]", 1);
            AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='xyz' and contains(., 'The Mother')]");
            AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='xyz' and contains(., 'Mama i tok')]");
            AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='fr' and contains(., 'The Mother')]");
            AssertThatXmlIn.Dom(dom).HasNoMatchForXpath("//div[@lang='fr' and contains(., 'Mama i tok')]");
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:33,代码来源:TranslationGroupManagerTests.cs

示例3: DeleteNodes

		public void DeleteNodes()
		{
			var dom = new XmlDocument();
			dom.LoadXml(@"<?xml version='1.0' encoding='utf-8'?>
<html>
	<body>
		<div class='A'><textarea>A1</textarea></div>
		<div class='B'><textarea>B</textarea></div>
		<div class='A'><textarea>A2</textarea></div>
	</body>
</html>");

			dom.DeleteNodes("descendant-or-self::*[contains(@class, 'A')]");
			Assert.AreEqual(1, dom.SafeSelectNodes("html/body/div").Count);
			Assert.AreEqual("<textarea>B</textarea>", dom.SafeSelectNodes("html/body/div")[0].InnerXml);
		}
开发者ID:JohnThomson,项目名称:libpalaso,代码行数:16,代码来源:XmlNodeExtensionsTests.cs

示例4: ChangePicture

        /// <summary>
        /// for testing.... todo: maybe they should test ProcessAndCopyImage() directly, instead
        /// </summary>
        public void ChangePicture(string bookFolderPath, XmlDocument dom, string imageId, PalasoImage imageInfo)
        {
            var matches = dom.SafeSelectNodes("//img[@id='" + imageId + "']");
            XmlElement img = matches[0] as XmlElement;

            var imageFileName = ProcessAndCopyImage(imageInfo, bookFolderPath);
            img.SetAttribute("src", imageFileName);
        }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:11,代码来源:PageEditingModel.cs

示例5: DescribeInitialContents

        public IEnumerable<IChangeReport> DescribeInitialContents(FileInRevision fileInRevision, TempFile file)
        {
            var dom = new XmlDocument();
            dom.Load(file.Path);

            foreach (XmlNode e in dom.SafeSelectNodes("notes/annotation"))
            {
                yield return new XmlAdditionChangeReport(fileInRevision, e);
            }
        }
开发者ID:sillsdev,项目名称:chack,代码行数:10,代码来源:ChorusNotesFileHandler.cs

示例6: PrepareElementsOnPage_HasLabelElementInsideTranslationGroup_LeavesUntouched

        public void PrepareElementsOnPage_HasLabelElementInsideTranslationGroup_LeavesUntouched()
        {
            var contents = @"<div class='bloom-page bloom-translationGroup'>
                        <label class='bloom-bubble'>something helpful</label>
                    </div>";
            var dom = new XmlDocument();
            dom.LoadXml(contents);

            TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//label[@class='bloom-bubble']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//label[@class='bloom-bubble' and text()='something helpful']", 1);
        }
开发者ID:jorik041,项目名称:BloomDesktop,代码行数:13,代码来源:TranslationGroupManagerTests.cs

示例7: PrepareElementsOnPage_HasEmptyTranslationGroup_MakesVernacularAndNational

        public void PrepareElementsOnPage_HasEmptyTranslationGroup_MakesVernacularAndNational()
        {
            var contents = @"<div class='bloom-page bloom-translationGroup'>
                    </div>";
            var dom = new XmlDocument();
            dom.LoadXml(contents);

            TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable') and @contenteditable='true' ]", 3);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='xyz']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 1);
        }
开发者ID:jorik041,项目名称:BloomDesktop,代码行数:14,代码来源:TranslationGroupManagerTests.cs

示例8: PrepareElementsOnPage_HasTextAreaInsideTranslationGroup_MakesVernacularAndNational

        public void PrepareElementsOnPage_HasTextAreaInsideTranslationGroup_MakesVernacularAndNational()
        {
            var contents = @"<div class='bloom-page bloom-translationGroup'>
                        <textarea lang='en'>This is some English</textarea>
                    </div>";
            var dom = new XmlDocument();
            dom.LoadXml(contents);

            TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], _collectionSettings.Object);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea", 4);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='en']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='fr']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='es']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='xyz']", 1);
        }
开发者ID:JohnThomson,项目名称:testBloom,代码行数:16,代码来源:TranslationGroupManagerTests.cs

示例9: PrepareElementsOnPage_HasNonEditableDiv_LeavesAlone

        public void PrepareElementsOnPage_HasNonEditableDiv_LeavesAlone()
        {
            var contents = @"<div class='bloom-page'>
                        <table class='bloom-translationGroup'> <!-- table is used for vertical alignment of the div on some pages -->
                         <td>
                            <div lang='en'>This is some English</div>
                        </td>
                        </table>
                    </div>";
            var dom = new XmlDocument();
            dom.LoadXml(contents);

            TranslationGroupManager.PrepareElementsInPageOrDocument((XmlElement)dom.SafeSelectNodes("//div[@class='bloom-page']")[0], _collectionSettings.Object);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//td/div", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//td/div[@lang='en']", 1);
        }
开发者ID:jorik041,项目名称:BloomDesktop,代码行数:17,代码来源:TranslationGroupManagerTests.cs

示例10: RemoveStyleSheetIfFound

		public static void RemoveStyleSheetIfFound(XmlDocument dom, string cssFilePath)
		{
			foreach (XmlElement linkNode in dom.SafeSelectNodes("/html/head/link"))
			{
				var href = linkNode.GetAttribute("href");
				if (href == null)
				{
					continue;
				}
				//strip it down to just the name+extension, so other forms (e.g., via slightly different urls) will be removed.
				var path = href.ToLower().Replace("file://", "");
				if(Path.GetFileName(path)==Path.GetFileName(cssFilePath.ToLower()))
				{
					linkNode.ParentNode.RemoveChild(linkNode);
				}
			}
		}
开发者ID:jwickberg,项目名称:libpalaso,代码行数:17,代码来源:XmlDomExtensions.cs

示例11: MergeConflictFiles_AncestorExistsButNoConflicts

        public void MergeConflictFiles_AncestorExistsButNoConflicts()
        {
            using (
                GroupOfConflictFiles group = new GroupOfConflictFiles("<notes/>",
                                                                      "<notes><annotation guid='bobGuid'/></notes>",
                                                                      "<notes><annotation guid='sallyGuid'/></notes>")
                )
            {
                MergeOrder order = new MergeOrder( group.BobFile.Path,
                                                  group.AncestorFile.Path, group.SallyFile.Path, new NullMergeSituation());
                new ChorusNotesFileHandler().Do3WayMerge(order);

                XmlDocument doc = new XmlDocument();
                doc.Load(group.BobFile.Path);
                Assert.AreEqual(2, doc.SafeSelectNodes("notes/annotation").Count);

            }
        }
开发者ID:sillsdev,项目名称:chack,代码行数:18,代码来源:ChorusMLFileSyncTests.cs

示例12: PrepareDataBookTranslationGroups_PlaceholdersCreatedAsNeeded

        public void PrepareDataBookTranslationGroups_PlaceholdersCreatedAsNeeded()
        {
            var contents = @"<div class='bloom-page'>
                                <div class='bloom-translationGroup'>
                                        <div class='bloom-editable' data-book='bookTitle' lang='en'>Some English</div>
                                </div>
                        </div>";
            var dom = new XmlDocument();
            dom.LoadXml(contents);

            var languages = new string[] {"en","es","fr"};
            TranslationGroupManager.PrepareDataBookTranslationGroups((XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0], languages);

            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div/div[contains(@class, 'bloom-editable')]", 3);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='fr']", 1);
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='es']", 1);
            //should touch the existing one
            AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='en' and text()='Some English']", 1);
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:19,代码来源:TranslationGroupManagerTests.cs

示例13: XmlDocument

 public void UpdateContentLanguageClasses_ExistingPageWith3rdLangRemoved_RemovesContentLanguageClassButLeavesOtherClasses()
 {
     var contents = @"<div class='bloom-page'>
                 <div class='bloom-translationGroup'>
                     <textarea lang='en'></textarea>
                     <textarea class='bloom-content2' lang='222'></textarea>
                     <textarea  class='foo bloom-content3 bar' lang='333'></textarea>
                     </div>
                 </div>";
     var dom = new XmlDocument();
     dom.LoadXml(contents);
     var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[contains(@class,'bloom-page')]")[0];
     TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, "xyz", _collectionSettings.Object.Language2Iso639Code, _collectionSettings.Object.Language3Iso639Code, "222", null);
     AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='222' and contains(@class, 'bloom-content2')]", 1);
     AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'bloom-content3')]", 0);
     AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'foo')]", 1);
     AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'bar')]", 1);
 }
开发者ID:jorik041,项目名称:BloomDesktop,代码行数:18,代码来源:TranslationGroupManagerTests.cs

示例14: MakeXmlishTagsSafeForInterpretationAsHtml

        /// <summary>
        /// If an element has empty contents, like <textarea></textarea>, browsers will sometimes drop the end tag, so that now, when we read it back into xml,
        /// anything following the <textarea> will be interpreted as part of the <textarea>!  This method makes sure such tags are never totally empty.
        /// </summary>
        /// <param name="dom"></param>
        public static void MakeXmlishTagsSafeForInterpretationAsHtml(XmlDocument dom)
        {
            foreach (XmlElement node in dom.SafeSelectNodes("//textarea"))
            {
                if (!node.HasChildNodes)
                {
                    node.AppendChild(node.OwnerDocument.CreateTextNode(""));
                }
            }
            foreach (XmlElement node in dom.SafeSelectNodes("//div"))
            {
                if (!node.HasChildNodes)
                {
                    node.AppendChild(node.OwnerDocument.CreateTextNode(""));
                }
            }

            foreach (XmlElement node in dom.SafeSelectNodes("//p"))
                //without  this, an empty paragraph suddenly takes over the subsequent elements. Browser sees <p></p> and thinks... let's just make it <p>, shall we? Stupid optional-closing language, html is....
            {
                if (!node.HasChildNodes)
                {
                    node.AppendChild(node.OwnerDocument.CreateTextNode(""));
                }
            }

            foreach (XmlElement node in dom.SafeSelectNodes("//span"))
            {
                if (!node.HasChildNodes)
                {
                    node.AppendChild(node.OwnerDocument.CreateTextNode(""));
                }
            }

            foreach (XmlElement node in dom.SafeSelectNodes("//script"))
            {
                if (string.IsNullOrEmpty(node.InnerText) && node.ChildNodes.Count == 0)
                {
                    node.InnerText = " ";
                }
            }

            foreach (XmlElement node in dom.SafeSelectNodes("//style"))
            {
                if (string.IsNullOrEmpty(node.InnerText) && node.ChildNodes.Count == 0)
                {
                    node.InnerText = " ";
                }
            }
        }
开发者ID:BloomBooks,项目名称:BloomDesktop,代码行数:55,代码来源:XmlHtmlConverter.cs

示例15: UpdateContentLanguageClasses_NewPage_AddsContentLanguageClasses

 public void UpdateContentLanguageClasses_NewPage_AddsContentLanguageClasses()
 {
     var contents = @"<div class='bloom-page'>
                 <div class='bloom-translationGroup'>
                     <textarea lang='en'></textarea>
                     <textarea lang='222'></textarea>
                     <textarea lang='333'></textarea>
                     </div>
                 </div>";
     var dom = new XmlDocument();
     dom.LoadXml(contents);
     var pageDiv = (XmlElement)dom.SafeSelectNodes("//div[@class='bloom-page']")[0];
     TranslationGroupManager.UpdateContentLanguageClasses(pageDiv, "xyz", _collectionSettings.Object.Language2Iso639Code, _collectionSettings.Object.Language3Iso639Code, "222", "333");
     AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='222' and contains(@class, 'bloom-content2')]", 1);
     AssertThatXmlIn.Dom(dom).HasSpecifiedNumberOfMatchesForXpath("//textarea[@lang='333' and contains(@class, 'bloom-content3')]", 1);
 }
开发者ID:jorik041,项目名称:BloomDesktop,代码行数:16,代码来源:TranslationGroupManagerTests.cs


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