xpath

xpath select referenced xml node

I need to select a node whose "name" attribute is equal to the current node's "references" attribute. <node name="foo" /> <node name="bar" references="foo" /> I couldn't find a way to express this in XPATH. Any ideas. Ive tried the following: ./node[@name=@references] ./node[@name={@references}] Obviously the above didn't work. I g...

LINQ to XML: applying an XPath

Can someone tell me why this program doesn't enumerate any items? Does it have something to do with the RDF namespace? using System; using System.Xml.Linq; using System.Xml.XPath; class Program { static void Main(string[] args) { var doc = XDocument.Load("http://seattle.craigslist.org/sof/index.rss"); foreach (...

xpath: how can you select a specific text node before and after a <br> tag ?

consider this List of Alcohol Beer <br> Vodka <br> rum <br> whiskey how would you express Beer in xpath ? /br/preceding-sibling::text() ? what about vodka ? rum ? ...

xpath: how to express text nodes ?

consider: text 1 text 2 text 3 how can you express the textnode in xpath ? ...

Xpath: how do you select the second text node (specific text node)

consider a html page <html> apple orange drugs </html> how can you select orange using xpath ? /html/text()[2] doesn't work. ...

why can't i wrap <span> around the rfollowing nokogiri xpath ?

doc = Nokogiri::HTML(open(url)).xpath("//*") .xpath("//*[br]/text()[string-length(normalize-space()) != 0]") .wrap("<span></span>") puts doc it just returns the text ... i was expecting the full html source with now wrapped around the specified xpath elements. ...

selecting specific text node with xpath ?

<html> apple <Br> orange <br> drugs </html> can you do something like //html/text()[2] it doesn't work. ...

Python xpath not working?

Okay, this is starting to drive me a little bit nuts. I've tried several xml/xpath libraries for Python, and can't figure out a simple way to get a stinkin' "title" element. The latest attempt looks like this (using Amara): def view(req, url): req.content_type = 'text/plain' doc = amara.parse(urlopen(url)) for node in doc.x...

Return value from XPathSelectElement(s) in C#

How do node.XPathSelectElement() and node.XPathSelectElements() behave when the selection is either not a NodeSet or a NodeSet containing non-Elements? For example do they always return something or can they throw Exceptions? can the return value be null or is it always an IEnumerable of some sort? The XML searched is constant: <a> <b...

How to traverse XPath recursively ?

Hi, is there a way (and if so, how ?) to traverse a XPath query recursively ? I have an AST in Java with the following scenario @Relevant public void foo() { bar(true); } public void bar(boolean flag) { assert flag; } I want to find the method which is annotated with '@Relevant' (thats easy) and check if the method which is ca...

Error parsing XML file in JavaScript

I'm trying to parse a simple XML file but I'm having trouble trying to obtain a value I need. The current error message I'm getting says node is not an object or is null. I'm testing on both I.E. 6, 7, FF 2,3 Here's the XML file: <bookstore> <appSettings> <add key="myKey" value="myTargetValue"/> </appSettings> </bookstore> He...

Beginner's XSLT question: Select node based on a value elsewhere in the XML structure

--edited for clarity (hopefully) I have an XML file that looks something like this: <questionBlock> <responses> . . . <response> <degree>1</degree> <instdegree>1</instdegree> </response> . . . </responses> <question> <variable>degree</variable> <text>Please select a degree o...

Xpath Query on HTML page - syntax?

Hi I have this URL:- http://ask.recipelabs.com/users and I wish to find the highest page number in the div id 'pager' (in this case it is 7) I have tried this but it returns zero: function getusers($url) { $doc = new DOMDocument; $doc->loadhtml($url); $xpath = new DOMXPath($doc); $nodelist = $xpath->query('//span[@class="page-numbe...

XHTML to XHTML with XSLT and its encodings

Hi there! I'm learning XSLT, and as an exercise, I'm trying to get the top links of http://ptchan.org/fa/, namely {al, az, fa, ga, li, tm}. To do so, I've created the following XSL Template: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.o...

XPathNavigator.SetValue Throws NotSupportedException

I have the following code, whose last line results in a NotSupportedException on every execution, and I haven't found a way around it. This hypothetical analogous code finds a "book" with a specific title, with the goal of updating it to the new title. It does find the correct node, but fails to update it. XPathDocument xpathDoc = new X...

XPath find a class?

In my webpage, there's a div class named Test. How can I find it with XPath? or am I doing it wrong? ...

XPath in Biztalk returns concatenated string values. Want Elements AND Values

I have a message which looks like this for example, but could have many more invoices contained within it: <ns1:InvoicesEnvelope xmlns:ns1="http://Test.Schemas.InvoiceEnvelope_1"xmlns:ns0="http://Test.Schemas.Invoices"&gt; <Invoices> <ns0:Invoice> <Header> <BatchID>1311</BatchID> <InvoiceNo>3400055151</InvoiceNo> <CustomerName>...

How can I use XPath with AS3 and get a result that still reffereced to the XMLDocument object?

I'm parsing a XML string into XMLDocument object. I want to search for a specific node using XPath technology by using XPathQuery.execQuery() - this function returns new XML object which means I need to convert it to a different XMLDocument object and lose the reference, how can I do that without loosing the reference? I'm using this XP...

Retrieving one element and filter by another

Having tried and failed to modify the XSL from here: http://stackoverflow.com/questions/399204/xslt-distinct-elements-and-grouping I'm posting here to ask if anyone could please help. I've basically got the same data structure (mine is actually an RSS feed of products) as in the above post, but I want to list the Description elements un...

Sorting xmlnodelist with XPATH, and convert back to xmlnodelist

Hi, I have an xmlnodelist in C# I would like sort by ID without creating arrays. The XML data is loaded into a dynamic table I've created. I haven't studied a lot XPATH but I figured out by Googling the attached code could work. Howevern, I would like to get the sorted output back as an xmlnodelist in order to create the dynamic table ea...