xpathnavigator

Which is the best for performance wise: XPathNavigator with XPath vs Linq to Xml with query?

有些话、适合烂在心里 提交于 2019-12-21 05:24:05
问题 I have an application in which I am using XPathNavigator to iterate nodes. It is working fine. But I want to know that if I use LINQ to Xml.... What benefits(Performance, maintainability) I will get? With XPath, LINQ to Xml what is the performance hit? I am using C#.net, VS 2010 and my .xml is mid size. 回答1: Well, XPathNavigator will generally be faster than Linq to XML queries. But there's always 'but'. Linq to XML will definitely make your code more readable and maintainable. It's easier

Implementing my own XPathNavigator in C#

 ̄綄美尐妖づ 提交于 2019-12-21 05:23:28
问题 I am looking for a C# example implementation of a class derived from Microsoft's XPathNavigator class. Can any one point me at such an article? As you may (or may not) know, the XmlNavigator is designed to allow one to superimpose XPath navigation on most any data model. I have implemented my derived XPathNavigator class and it works very well. Very well that is except for XPath expressions that search recursively, i.e. "//*". I am pretty sure that I have a subtle bug in the Clone,

Using Xpath With Default Namespace in C#

拜拜、爱过 提交于 2019-12-16 19:47:15
问题 I've got an XML document with a default namespace. I'm using a XPathNavigator to select a set of nodes using Xpath as follows: XmlElement myXML = ...; XPathNavigator navigator = myXML.CreateNavigator(); XPathNodeIterator result = navigator.Select("/outerelement/innerelement"); I am not getting any results back: I'm assuming this is because I am not specifying the namespace. How can I include the namespace in my select? 回答1: First - you don't need a navigator; SelectNodes / SelectSingleNode

Using Xpath With Default Namespace in C#

风格不统一 提交于 2019-12-16 19:44:29
问题 I've got an XML document with a default namespace. I'm using a XPathNavigator to select a set of nodes using Xpath as follows: XmlElement myXML = ...; XPathNavigator navigator = myXML.CreateNavigator(); XPathNodeIterator result = navigator.Select("/outerelement/innerelement"); I am not getting any results back: I'm assuming this is because I am not specifying the namespace. How can I include the namespace in my select? 回答1: First - you don't need a navigator; SelectNodes / SelectSingleNode

Easy XPathNavigator GetAttribute

送分小仙女□ 提交于 2019-12-12 09:39:25
问题 Just getting started here with my first take at XPathNavigator . This is my simple xml: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <theroot> <thisnode> <thiselement visible="true" dosomething="false"/> <another closed node /> </thisnode> </theroot> Now, I am using the CommonLibrary.NET library to help me a little: public static XmlDocument theXML = XmlUtils.LoadXMLFromFile(PathToXMLFile); const string thexpath = "/theroot/thisnode"; public static void test() { XPathNavigator xpn

VB.NET XPathDocument.CreateNavigator throws “debuggerDisplayProxy” error

余生长醉 提交于 2019-12-11 10:26:42
问题 I'm new to this and working from a tutorial. I have a variation on the following code: Dim xDoc As XPathDocument Dim xNav As XPathNavigator xDoc = New XPathDocument("xxxxxxx.xml") xNav = xDoc.CreateNavigator() However, "CreateNavigator" returns: 'debuggerDisplayProxy' is a type and cannot be used as an expression. I've Googled and searched and found nothing (although I'm not really sure what to look for). This seems like something basic and it's stopping me from continuing with a lot of other

Get full XPath from partial

落爺英雄遲暮 提交于 2019-12-07 13:36:00
问题 I am using selenium with perl and have label on page, to access this label i have following xpath: //*[text()='some here'] , the problem that a need to get full xpath of this element, like /html/body/table/tr/..../any other/and other/ , is there is any selenium method or perl function ? looking for perl solution or any other working things. thanks 回答1: looking for perl solution or any other working things This XPath 2.0 expression: string-join(for $node in ancestor-or-self::node() return

Get full XPath from partial

时光怂恿深爱的人放手 提交于 2019-12-05 18:32:25
I am using selenium with perl and have label on page, to access this label i have following xpath: //*[text()='some here'] , the problem that a need to get full xpath of this element, like /html/body/table/tr/..../any other/and other/ , is there is any selenium method or perl function ? looking for perl solution or any other working things. thanks looking for perl solution or any other working things This XPath 2.0 expression: string-join(for $node in ancestor-or-self::node() return concat(('@')[$node/self::attribute()], $node/name(), (concat('[', count($node/preceding-sibling::node() [name()=

Easy XPathNavigator GetAttribute

橙三吉。 提交于 2019-12-05 07:46:34
Just getting started here with my first take at XPathNavigator . This is my simple xml: <?xml version="1.0" encoding="utf-8" standalone="yes"?> <theroot> <thisnode> <thiselement visible="true" dosomething="false"/> <another closed node /> </thisnode> </theroot> Now, I am using the CommonLibrary.NET library to help me a little: public static XmlDocument theXML = XmlUtils.LoadXMLFromFile(PathToXMLFile); const string thexpath = "/theroot/thisnode"; public static void test() { XPathNavigator xpn = theXML.CreateNavigator(); xpn.Select(thexpath); string thisstring = xpn.GetAttribute("visible","");

Get attribute values from matching XML nodes using XPath query

最后都变了- 提交于 2019-12-04 18:04:07
问题 This doesn't seem like it should be difficult, but I'm stuck currently. I'm trying to get the attribute values for a particular attribute from nodes that match a given XPath query string. Here's what I have so far: public static IEnumerable<string> GetAttributes(this XmlDocument xml, string xpathQuery, string attributeName) { var doc = new XPathDocument(new XmlNodeReader(xml)); XPathNavigator nav = doc.CreateNavigator(); XPathExpression expr = nav.Compile(xpathQuery); XPathNodeIterator