public void Init()
		{
			string xml = "<root xmlns='http://foo.com'/>";
			XPathQuery query = new XPathQuery(xml);
			nodes = query.FindNodes("//namespace::*");
			node = nodes[0];
			xmlNamespaceNode = nodes[1];
		}
예제 #2
0
        public void CommentNodeFoundByXPath()
        {
            string xml = "<!-- Test --><root/>";
            XPathQuery query = new XPathQuery(xml);
            XPathNodeMatch[] nodes = query.FindNodes("//comment()");
            XPathNodeMatch node = nodes[0];

            string nodeValue = " Test ";
            string displayValue = "<!-- Test -->";
            int lineNumber = 0;
            int linePosition = 4;
            XPathNodeType nodeType = XPathNodeType.Comment;
            XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
        }
예제 #3
0
        public void AttributeNodeFoundByXPath()
        {
            string xml = "<root>\r\n" +
                "\t<foo Id='ab'></foo>\r\n" +
                "</root>";
            XPathQuery query = new XPathQuery(xml);
            XPathNodeMatch[] nodes = query.FindNodes("//foo/@Id");
            XPathNodeMatch node = nodes[0];

            string nodeValue = "Id";
            string displayValue = "@Id";
            int lineNumber = 1;
            int linePosition = 6;
            XPathNodeType nodeType = XPathNodeType.Attribute;
            XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
            XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
            Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
        }
		public void EmptyCommentNode()
		{
			string xml = "<!----><root/>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//comment()");
			
			ServiceContainer container = new ServiceContainer();
			container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());
			
			IDocument doc = new ICSharpCode.AvalonEdit.Document.TextDocument() { ServiceProvider = container };
			doc.Text = xml;
			XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
			xpathNodeMarker.AddMarkers(nodes);
			
			ITextMarkerService service = doc.GetService(typeof(MockTextMarkerService)) as ITextMarkerService;
			List<ITextMarker> markers = new List<ITextMarker>(service.TextMarkers);
			
			Assert.AreEqual(0, markers.Count);
			Assert.AreEqual(1, nodes.Length);
		}
		public void Init()
		{
			string xml = "<root><foo/></root>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//root");
			
			IDocument doc = MockTextMarkerService.CreateDocumentWithMockService();
			doc.Text = xml;
			XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
			xpathNodeMarker.AddMarkers(nodes);
			
			ITextMarkerService service = doc.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
			markers = new List<ITextMarker>(service.TextMarkers);
			
			// Remove markers.
			XPathNodeTextMarker.RemoveMarkers(doc);
			markersAfterRemove = new List<ITextMarker>(service.TextMarkers);
			
			xpathNodeTextMarker = markers[0];
		}
예제 #6
0
		public void SingleEmptyElementNodeFoundByXPath()
		{
			string xml = 
				"<root>\r\n" +
				"\t<foo/>\r\n" +
				"</root>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//foo");
			XPathNodeMatch node = nodes[0];
			
			string nodeValue = "foo";
			string displayValue = "<foo/>";
			int lineNumber = 1;
			int linePosition = 2;
			XPathNodeType nodeType = XPathNodeType.Element;
			XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
			XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
			Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
			Assert.AreEqual(1, nodes.Length);
		}
		public void NamespaceQuery()
		{
			string xml = 
				"<?xml version='1.0'?>\r\n" +
				"<Xml1></Xml1>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//namespace::*");
			
			ServiceContainer container = new ServiceContainer();
			container.AddService(typeof(MockTextMarkerService), new MockTextMarkerService());
			
			IDocument doc = new ICSharpCode.AvalonEdit.Document.TextDocument() { ServiceProvider = container };
			doc.Text = xml;
			XPathNodeTextMarker xpathNodeMarker = new XPathNodeTextMarker(doc);
			xpathNodeMarker.AddMarkers(nodes);
			
			ITextMarkerService service = doc.GetService(typeof(MockTextMarkerService)) as ITextMarkerService;
			List<ITextMarker> markers = new List<ITextMarker>(service.TextMarkers);
			
			Assert.AreEqual(0, markers.Count);
			Assert.AreEqual(1, nodes.Length);
		}
예제 #8
0
		public void SingleElementWithNamespacePrefixFoundByXPath()
		{
			string xml = 
				"<f:root xmlns:f='http://foo.com'>\r\n" +
				"\t<f:foo></f:foo>\r\n" +
				"</f:root>";
			XmlNamespaceCollection namespaces = new XmlNamespaceCollection();
			namespaces.Add(new XmlNamespace("fo", "http://foo.com"));
			XPathQuery query = new XPathQuery(xml, namespaces);
			XPathNodeMatch[] nodes = query.FindNodes("//fo:foo");
			XPathNodeMatch node = nodes[0];
			
			string nodeValue = "f:foo";
			string displayValue = "<f:foo>";
			int lineNumber = 1;
			int linePosition = 2;
			XPathNodeType nodeType = XPathNodeType.Element;
			XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
			XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
			Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
			Assert.AreEqual(1, nodes.Length);
		}
예제 #9
0
        void RunXPathQuery()
        {
            XmlView xmlView = XmlView.ActiveXmlView;

            if (xmlView == null)
            {
                return;
            }

            try {
                fileName = xmlView.File.FileName;

                // Clear previous XPath results.
                ClearResults();
                XPathNodeTextMarker.RemoveMarkers(xmlView.TextEditor.Document);

                // Run XPath query.
                XPathQuery       query = new XPathQuery(xmlView.TextEditor, GetNamespaces());
                XPathNodeMatch[] nodes = query.FindNodes(xpathComboBox.Text);
                if (nodes.Length > 0)
                {
                    AddXPathResults(nodes);
                    XPathNodeTextMarker marker = new XPathNodeTextMarker(xmlView.TextEditor.Document);
                    marker.AddMarkers(nodes);
                }
                else
                {
                    AddNoXPathResult();
                }
                AddXPathToHistory();
            } catch (XPathException xpathEx) {
                AddErrorResult(xpathEx);
            } catch (XmlException xmlEx) {
                AddErrorResult(xmlEx);
            } finally {
                BringResultsTabToFront();
            }
        }
예제 #10
0
        void RunXPathQuery()
        {
            XmlView xmlView = XmlView.ActiveXmlView;
            if (xmlView == null) {
                return;
            }

            try {
                fileName = xmlView.File.FileName;

                // Clear previous XPath results.
                ClearResults();
                XPathNodeTextMarker.RemoveMarkers(xmlView.TextEditor.Document);

                // Run XPath query.
                XPathQuery query = new XPathQuery(xmlView.TextEditor, GetNamespaces());
                XPathNodeMatch[] nodes = query.FindNodes(xpathComboBox.Text);
                if (nodes.Length > 0) {
                    AddXPathResults(nodes);
                    XPathNodeTextMarker marker = new XPathNodeTextMarker(xmlView.TextEditor.Document);
                    marker.AddMarkers(nodes);
                } else {
                    AddNoXPathResult();
                }
                AddXPathToHistory();
            } catch (XPathException xpathEx) {
                AddErrorResult(xpathEx);
            } catch (XmlException xmlEx) {
                AddErrorResult(xmlEx);
            } finally {
                BringResultsTabToFront();
            }
        }
예제 #11
0
		public void NoXPathNodeFoundForUnknownElementInXPathQuery()
		{
			string xml = 
				"<root>\r\n" +
				"\t<foo/>\r\n" +
				"</root>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//bar");
			Assert.AreEqual(0, nodes.Length);
		}
예제 #12
0
		public void ProcessingInstructionNodeFoundByXPath()
		{
			string xml = "<root><?test processinstruction='1.0'?></root>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//processing-instruction()");
			XPathNodeMatch node = nodes[0];
			
			string nodeValue = "test";
			string displayValue = "<?test processinstruction='1.0'?>";
			int lineNumber = 0;
			int linePosition = 8;
			XPathNodeType nodeType = XPathNodeType.ProcessingInstruction;
			XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
			XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
			Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
		}
예제 #13
0
		public void TextNodeMatchedWithXPath()
		{
			string xml = 
				"<root>\r\n" +
				"\t<foo>test</foo>\r\n" +
				"</root>";
			XPathQuery query = new XPathQuery(xml);
			XPathNodeMatch[] nodes = query.FindNodes("//foo/text()");
			XPathNodeMatch node = nodes[0];
			
			string nodeValue = "test";
			string displayValue = "test";
			int lineNumber = 1;
			int linePosition = 6;
			XPathNodeType nodeType = XPathNodeType.Text;
			XPathNodeMatch expectedNode = new XPathNodeMatch(nodeValue, displayValue, lineNumber, linePosition, nodeType);
			XPathNodeMatchComparison comparison = new XPathNodeMatchComparison();
			Assert.IsTrue(comparison.AreEqual(expectedNode, node), comparison.GetReasonForNotMatching());
			Assert.AreEqual(1, nodes.Length);
		}