xpath

How to extract leaf nodes and path of parent elements from an XSD

I'm trying to transform an XML Schema document and extract a list of all leaf element names and the path of their parent elements, i.e. the names of each element that ref's the current element, and the element that ref's that one, on up to only element that's not referred to by another ref attribute. I'm not getting anywhere, so I don't ...

using XPath to find node under a context node does not work (firefox/firebug/javascript)

I want to extract information from a web page. The page has m nodes, which can be found by .evaluate("//div[@class='news']", document, ....). For each of the above nodes, there are 3 nodes inside them. Each of them has different @class selector. And I want to extract these m 3-tuple records. I tried to use .evaluate() function as inst...

Object tree navigation language in Java

In the system which I'm currently developing I often have to navigate an object tree and based on its state and values take actions. In normal Java this results in tedious for loops, if statements etc... Are there alternative ways to achieve tree navigation, similar to XPath for XML? I know there is JXPath and OGNL, but do you know any o...

XPath to find elements that does not have an id or class

How can I get all tr elements without id attribute? <tr id="name">...</tr> <tr>...</tr> <tr>...</tr> Thanks ...

Get Nth child of a node using xpath

Hi, My sample input XML is: <root> <a> <b>item</b> <b>item1</b> <b>item2</b> <b>item3</b> <b>item4</b> </a> </root> I am suppose to select a node "b" whose position is the value of a variable, how to use the value of variable to test the position of a node? Best Reagards, Iordan ...

I can't use dashes in XPATH on iphone using libxml2

I'm trying to parse HTML data using KissXML for iphone. I've noticed that I can't have dashes in the id() tag, otherwise it won't evaluate. For example, if I'm trying to get the element at I would do id("foo") However, if I try to get at element , and I try id("foo-bar") the libxml2 XPATH engine doesn't seem to return anything. It w...

XPath Invalid Expression

<?php $feed = file_get_contents('http://thexmofo.wordpress.com/feed/'); $xml = new SimpleXMLElement($feed); $xml->registerXPathNamespace('media', 'http://thexmofo.wordpress.com/feed/'); $images = $xml->xpath('/rss/channel/item/media:content@url'); var_dump($images); ?> Can anyone tell my why I'm getting Warning: SimpleXMLElem...

How do I return '' for an empty node's text() in XPath?

<td></td><td>foo</td> I would like to return ['', 'foo'] but libxml's xpath //td/text() returns just ['foo']. How do I find the empty tag as '' instead of (not matched)? ...

xQuery local-name vs xPath with html

assuming the following html (minus the comments and "nbsp;" etc that xQuery wont process as is) why does this following code work for $first in fn:doc("file:///index.html")//element()[local-name() = "head"] return <test>{ $first }</test> and this for $first in fn:doc("file:///index.html")//head return <test>{ $first }</test> ...

xPath Groupings how?

OK So, I'm learning/using xpath for a basic application that's effectively ripping data off another website. I need to gain the knowledge of each persons Country/Suburb/area. In some instances you can get Australia/Victoria/Melbourne for instance. Others may just be Australia/Melbourne. Or even just Melbourne OR just Australia. So I'...

XPath to find elements with attributes

How can I find elements that has at least one attribute? Example: <tr>...</tr> <tr style="">...</tr> <tr width="">...</tr> I want all tr elements but ... I tried following xpath but it doesn't work. //table//tr[contains(attributes::*,'')] Thanks ...

Is dynamic evaluation of XPath variable string possible using .NET 2.0 XSLT implementation?

I'm trying to evaluate an XPath varable I'm building dynamically based on the position of the node. I can create the XPath string in a variable but when I select the value of this just get the string and not the node set I need. I use the following to create the XPath query. <xsl:variable name="xpathstring" select="no...

Define keyref selector based on element type in XPath

Let's say I have an XML file that will look like this: <a> <b d="value1"/> <c d="value2"/> </a> In the XSD file that defines the structure of this XML file I defined the elements by name 'b' and 'c' to be of the same type (and the type requires attribute 'd'). Let's say that I want to make a keyReference of all elements of th...

xpath for-each multiple conditions

What is wrong with the following line? <xsl:for-each select="//Node1/Node2/Node3 [.!='Primary' or .!='Secondary' ]"> Trying to select all elements where Node3 is not Primary o Secondary. Thanks. ...

xslt (table) by matching the attribute value.

I need to generate an xsl table for the xml below, for attributes fname and lname. I guess I have done something wrong in xpath. Could someone help me out by writing an xsl table for the xml below.. <sparql> <head> <variable name="s"/> <variable name="fname"/> <variable name="lname"/> </head> <results...

XPATH remove attribute

Hi does anyone know hwo to remove an attrbute using xpath. In particular the rel attribute and its text from a link. i.e. <a href='http://google.com' rel='some text'>Link</a> and i want to remove rel='some text'. There will be multiple links in the html i am parsing. ...

Get node parent of defined type using xpath

Hi, i will give an example of the problem i have. My XML is like this <root> <child Name = "child1"> <node> <element1>Value1</element1> <element2>Value2</element2> </node> </child> <child Name = "child2"> <element1>Value1</element1> <element2>Value2</element2> <element3>Value3</element3> </child> </root> I have x...

Problem with Xpath PHP

Im tring to access some links through Google using xpath. The below does works fine and all the links are shown. $query = $xpath->evaluate("/html/body//a"); for ($x=0 ; $x < $query -> length; $x++) { $href=$query->item($x); $url=$href->getAttribute('href'); echo $url."<br>"; } But when ...

Tentative date casting in tsql

I am looking for something like TRYCAST in TSQL or an equivalent method / hack. In my case I am extracting some date data from an xml column. The following query throws "Arithmetic overflow error converting expression to data type datetime." if the piece of data found in the xml cannot be converted to datetime (in this specific case, ...

etree.findall: 'OR'-lookup?

I want to find all stylesheet definitions in a XHTML file with lxml.etree.findall. This could be as simple as elems = tree.findall('link[@rel="stylesheet"]') + tree.findall('style') But the problem with CSS style definitions is that the order matters, e.g. <link rel="stylesheet" type="text/css" href="/media/css/first.css" /> <style>b...