xpath

Xpath noob: querying an xml element using xpath and a unique attribute?

I am querying a particularly ugly HTML file using xpath. I want to extract an HTML table that is buried deep within the document. However instead of going down through the hierarchy from //html/, is there anyway I can just reference the table's unique id attribute? Obviously this would have far less chance of breaking due to page edit...

xsl recursive loop node by index

I have created a recursive template for getting the first n number of items from my XML. It uses an index(counter) just like how I would in a for loop. Now how can I get a node from my XML using the index? I have tried [position()=$index] but it had weird behaviour when trying to get deeper nodes in the XML hierarchy. If I have XML su...

How to display XSD validated XML using XSLT

I've been fighting with this for some time now, and haven't been able to find a clear answer to this yet. As I understand correctly I can store data in an XML file, validate it using an XSD and then display the data neatly using an XSLT. However I've been having issues trying to perform XPath queries to select the data I wish to displa...

Selecting Comments by their inner xml in xpath/xsl

Hi, Given the following xml document <root> <childnode0/> <childnode2/> <!--Comment1--> <childnode3/> <childnode4/> <!--Comment2--> </root> I know the xpath to select all the comments at a particular level in xsl string xPath = "/root/comment()"; However i'd like to select a comment where the inner xml is "Commen...

XPath Expression must evaluate to a node-set with OK XPath Path (Tested with online XPath tester and Oxygen)

The program I am working on is having a null reference exception whenever it tries to delete the node. The buggy code: First one is where the variable is declared for getting the name of the node to be deleted foreach (XmlNode InstalledListNodes in PackagesNode) { //If the title is the same as what...

nokogiri multiple css classes

How is it possible to select an html element that have two classes. For example, hot to select the element p bellow in an html document (given that it has two css classes) class='class1 class2' : I tried to use the following : doc.xpath("//p[@class~='class1 class2']") doc.xpath("//p[@class~='class1']|[@class~='class2']") doc.xpath("...

VTD XML inner XPath Expressions

Hi I have a xml file for example like this <root> <test> <bla>test1</bla> </test> <test> <bla>test2</bla> </test> <test> </test> </root> Now I want to parse it with the vtd-xml-parser by using XPath Expressions. First I search for the test tags by VTDNav vn = vg.getNav(); AutoPilot ap = new AutoPilot(vn); ap.selectXPath("//...

SelectSingleNode always returns null?

Taking this simplifed example of my XML: <?xml version="1.0"?> <message xmlns="http://www.mydomain.com/MyDataFeed" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mydomain.com/MyDataFeed https://secure.mydomain/MyDataFeed/myDataFeed.xsd" requestId="13898" status="1"> <error>Invalid Login</error> </me...

Pulling content from one node only

I am trying to pull a specific node from my xml document, but continue to get content from all nodes. I am testing for a specific jNumber by passing the number to the xslt in a variable set with the fragment call ($jNumber). <xsl:if test="products/product/jNumber[. = $jNumber]"> <div class="floatLeft padTop10 margLeft10" style="width:...

Fastest/One-liner way to get XML nodes into array of "path/to/nodes" in Ruby?

What is the fastest, one-liner/shortest way to get an Array of "strings/that/are/paths" from an XML file, using Nokogiri preferably. I'd like to build the array with an arbitrary attribute name ('id' in this case), but also knowing how to do it for the element name would be helpful. So this: <root id="top"> <nodeA id="almost_top"...

XSLT: deep child copy

My need: I want to deep copy all the childs of a single selected node without actually copying it. Example: from <father><son i="1" /><son i="2" /><son i="0"><lastNode /></son></father> i wish to extract <son i="1" /><son i="2" /><son i="0"><lastNode /></son> I know that i can do this with a cycle for-each and then a xsl:copy-of....

XPath, XSL: How to select all nodes, not just elements, when xsl:param is a node-set?

In an XSL recursion, this <xsl:with-param name="items" select="$items[position() > 1] would normally work to recurse with all nodes but the first. But it only works if the nodes are elements. If they are a mix of element and text nodes, the recursion fails, since, for example, $items[3] returns the third element node, not the third n...

ASP.NET 2.0: how to use XPath?

Hello guys: If we can get a collection of x nodes via XPath in ASP.NET 2.0? Then doing checking per the attrs of them. <x-list> <x id="1" enable="On" url="http://abc.123.dev"/&gt; <x id="2" enable="Off" url="http://asd.com"/&gt; <x id="3" enable="On" url="http://plm.xcv.tw"/&gt; </x-list> Thanks for any help. Ricky ...

C#: XPath to select node with attribute containing a substring?

Hi folks: Could I use XPath to select country node whose code containing UK? <country-list> <Country code="TW,UK,MY" /> <Country code="US,CA,MX" /> <Country code="IN,PR,VI,IR" /> <Country code="Others" /> </country-list> Thanks. ...

XPath (C#) throw an exception: Namespace Manager or XsltContext needed

Hello folks: I ask a question about using XPath function there But I meet a problem about this exception: [System.Xml.XPath.XPathException] = {"Namespace Manager or XsltContext needed. This query has a prefix, variable, or user-defined function."} The xml is as follows: <x-config> <!--user location--> <x-list> <Cou...

html nested tables agility pack valid xpath

Assuming nested tables don't have unique attributes ( id , class or anything else ) to get the required one via doc.DocumentNode.SelectSingleNode("//table[@width='500']") Does XPath prohibit using table several times in its path ? foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table/tr/center/table")) throws excepti...

XPath expression to select all XML child nodes except a specific list?

Here's the sample data: <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <customField1>Whatever</customField1> <customField2>Whatever</customField2> <customField3>Whatever</customField3> <company>Columbia</company> ...

Getting content of a div (including child tags) with DOM

Hi, i am using DOM to get content of div tag but inner html part is not shown. Function is: $dom = new DOMDocument; libxml_use_internal_errors(true); $dom->loadHTMLFile("$url"); libxml_use_internal_errors(false); $xpath = new DOMXPath($dom); $divTag = $xpath->query('//div[@id="post"]'); foreach ($divTag as $val) { echo $val->getAttribut...

changing value of xml attribute queried by xpath query ?

I use javascript xpath queries (document.evaluate(...)) to read and modify parts of xml/svg/html documents. Setting the nodeValue of queried element and text nodes is no problem. but when setting attribute values, it is indeed set, but not reflected on the attribute DOM Node. It looks like xpath queries for attribute nodes return (name...

Is there a way to dynamically get an xpath of an element during runtime in Selenium

Is there a way to return the xpath of an element in Selenium during runtime whos xpath changes every time you return to the page? I need to extract a random number from the xpath of the element. Ex: //div[@id='element_id-87462'] where 87462 is a new random number everytime the element is loaded. I want to be able to extract 87462 so I...