예제 #1
0
        public IList <SearchResult> Search(string xpath)
        {
            if (string.IsNullOrWhiteSpace(xpath))
            {
                return(new SearchResult[0]);
            }

            var rootElement = _repository.GetRootElement();

            if (rootElement == null)
            {
                return(new SearchResult[0]);
            }

            try
            {
                var namespaceResolver = new SimpleXmlNamespaceResolver(rootElement.Document);
                var matches           = rootElement.Document?.XPathEvaluate(xpath, namespaceResolver);
                var searchResults     = _searchResultFactory.Parse(matches);
                return(searchResults);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(PackageResources.XPathEvaluationErrorText, ex);
            }
        }
예제 #2
0
        public void TriesToIgnoreDtdProcessingAsAFallback()
        {
            // Arrange
            var xml        = "<?xml version='1.0'?><!DOCTYPE datasets SYSTEM 'http://127.0.0.1/this-DTD-does-not-exist.dtd'><root />";
            var repository = new XmlRepository();

            // Act
            repository.LoadXml(xml, "http://127.0.0.1");

            // Assert
            Assert.That(repository.GetRootElement(), Is.Not.Null);
        }
예제 #3
0
        public void ResetXmlOnLoad()
        {
            // Arrange
            var repository = new XmlRepository();

            repository.LoadXml("<this-is-xml />", null);

            // Act
            repository.LoadXml("This is not XML.", null);

            // Assert
            Assert.That(repository.GetRootElement(), Is.Null);
        }
 private void StoreCurrentNode(string xml, int lineNumber, int linePosition)
 {
     try
     {
         _repository.LoadXml(xml, _activeDocument.AbsolutePath);
         var rootElement       = _repository.GetRootElement();
         var selectedElement   = _repository.GetElement(rootElement, lineNumber, linePosition);
         var selectedAttribute = _repository.GetAttribute(selectedElement, lineNumber, linePosition);
         _repository.SetSelected((XObject)selectedAttribute ?? selectedElement);
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.ToString());
     }
 }
예제 #5
0
        public void HandlesValidDtdUriReferencesGracefully()
        {
            // Arrange
            var xml        = XHTML;
            var repository = new XmlRepository();
            var stopwatch  = new Stopwatch();

            // Act
            stopwatch.Start();
            repository.LoadXml(xml, null);
            stopwatch.Stop();

            // Assert
            Assert.That(repository.GetRootElement(), Is.Not.Null);
            Assert.That(stopwatch.Elapsed, Is.LessThan(TimeSpan.FromSeconds(2)));
        }
예제 #6
0
        public void HandlesAbsoluteDtdReferencesGracefully()
        {
            // Arrange
            var xmlFilePath = Path.GetTempFileName();

            File.WriteAllText(xmlFilePath, XML);

            var dtdFilePath = Path.GetTempFileName();

            File.WriteAllText(dtdFilePath, DTD);

            var xml        = File.ReadAllText(xmlFilePath).Replace(DtdFilePlaceholder, dtdFilePath);
            var repository = new XmlRepository();

            // Act
            repository.LoadXml(xml, null);

            // Assert
            Assert.That(repository.GetRootElement(), Is.Not.Null);
        }
        public void ResetXmlOnLoad()
        {
            // Arrange
            var repository = new XmlRepository();
            repository.LoadXml("<this-is-xml />");

            // Act
            repository.LoadXml("This is not XML.");

            // Assert
            Assert.That(repository.GetRootElement(), Is.Null);
        }