xpath

Child's index with XPath

I'm hacking the OOXML format with XPath and it contains some 0-based arrays. What I want to do is get the indices of individual elements. For example: <parentNode> <childNode type="string" /> <childNode type="integer" /> <childNode type="boolean" /> </parentNode> Here I can find the desired element with the expression "/...

reading xml: can xpath read 2 fields?

I'm using SimpleXMLElement and xpath to try and read the <subcategory><name> from the xml at the very bottom. This code works.. but the stuff inside the while loop looks a little messy, and now I also want to get the <subcategory><count> and somehow pair it with its appropriate <subcategory><name>. $names = $xml->xpath('/theroot/categor...

How to read xpath values from many HTML files in .Net?

Howdy, I have about 5000 html files in a folder. I need to loop through them, open, grab say 10 values using xpath, close, and store in (SQL Server) DB. What is the easiest way to do read the xpath values using .Net? The xpaths should be pretty stable. Please provide example code to read one value, say /html/head/title/text() Than...

XPath query. Preceding-sibling of a conditionaly reduced set of nodes.

Hi, I got html code like the following: <p style="margin:0 0 0.5em 0;"><b>Blablub</b></p> <table> ... </table> Now I want to query the content of the <b> right above the table but only if the table does not have any attributes. I tried the following query: //table[not(@*)]/preceding-sibling::p/b If I remove the preceding-sibling::p...

c# can't read element attribute with xpath

This code can't read a specific attribute - the name attribute more specifically. Instead it read the text of node elements and does a concat on them - result: 1F20 is added to the list var reader = new StringReader(xml); var xmlreader = new XmlTextReader(reader); xmlreader.WhitespaceHandling = WhitespaceHandling...

What is the xpath to select a range of nodes?

Hi I have an XML file that's structured like this: <foo> <bar></bar> <bar></bar> ... </foo> I don't know how to grab a range of nodes. could someone give me an example of an xpath expression that grabs bar nodes 100-200. ...

XSL show attribute name

So, using that <xsl:for-each select="./@*"> [<xsl:value-of/><xsl:value-of select="."/>] </xsl:for-each> I can iterate over attribute values. But I want to see attribute names too. I want see a table: attr1 - val1 attr2 - val2 attr3 - val3 ... Thanks for help! ...

Why isn't document.evaluate working?

I am using this in a Firefox extension and can't get it to work. var allLinks = document.evaluate( '//a[@href]', window.document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); window.alert(allLinks); This alerts "[object XPathResult]". However the following always returns "0". (And...

XPath to select attribute

Hi, I need to select a node with a id attribute that i only know part of the value. if i have several: <tr id="foobar[1234]"></td><tr id="foobar[1235]"></td><tr id="foobar[1236]"></td><tr id="bar[1]"></td><tr id="foobar[1237]"></td><tr id="bar[12]"></td> i only want to select the id's that start with foobar. I've tried //tr[@id='f...

xpath php sort attribute based on greater than date

Need to xpath xml data based on greater than date attribute. The dashes in the date below prevent the greater than symbol from working. Is there a way to remove the dashes in the xml on the fly? XML <revisions> <revision date="2010-07-12">blah</revision> <revision date="2010-06-12">blah</revision> </revisions> PHP $rdate = 2010-...

Is it possible to apply normalize-space to all nodes XPath expression finds?

Consider simple XML document: <html><body> <table> <tr><td> Item 1</td></tr> <tr><td> Item 2</td></tr> </table> </body></html> Using XPath "/html/body/table/tr/td/text()" we will get [" Item 1", " Item 2"]. Is it possible to trim white space for example using normalize-space() function to get ["Item 1", "Item 2"]? "normalize-...

use xpath to select all attributes in a element and add those to a list

My xml: <Scenes> <Scene Index="0" Channel="71" Name="Scene1" /> <Scene Index="1" Channel="71" Name="Scene2" /> <Scene Index="2" Channel="71" Name="Scene3" /> </Scenes> My code: var elements = new List<List<string>>(); var attributtes = new List<string>(); XPathExpression expr1 = nav.Compile("//Scene/@*"); XPathN...

Library to query HTML with XPath in Java?

Can anyone recommend me a java library to allow me XPath Queries over URLs? I've tried JAXP without success. Thank you. ...

what is current() in predicate of predicate

Hello, another XPath/XSL question :) If i have a node tree like: A -- B (anymal-types=pets) ---- C (type=bird) ---- C (type=cat) ---- C (type=dog) -- B (working-animals) ---- C (type=cow) ---- C (type=elephant) -A ... and another xml file ($xmlFile) that lists types that one needs for the...

How to parse RSS link (get ulr to RSS) from the page in Python framework Scrapy?

Hello. I want to parse Google search and get links to RSS from each item from the search results. I use Scrapy. I tried this construction, ... def parse_second(self, response): hxs = HtmlXPathSelector(response) qqq = hxs.select('/html/head/link[@type=application/rss+xml]/@href').extract() print qqq item = response.req...

XPATH based content extraction from html pages

Hi, I m trying to extract content based on given xpath. When it is just one element i want to extract, there is no issue. When I have a list of items matching that xpath, then i get the nodelist and i can extract the values. However, there are a couple items related to each other forming a group, and that group repeats itself. One way ...

XPath query for GPX files with namespaces?

I am able to access the<trkpt></trkpt>nodes by the xpath expression<xsl:for-each select='gpx/trk/trkseg/trkpt'> when the GPX file has the following simple structure: <gpx> <trk> <trkseg> <trkpt lat="50.5324906" lon="7.0842605"> <ele>105.8824463</ele> <time>2010-07-11T08:50:16Z</time> </trkpt> <trk...

Python and libxml2: how to iterate in xml nodes with XPATH

I have a problem with retrieving information from a XML tree. My XML has this shape: <?xml version="1.0"?> <records xmlns="http://www.mysyte.com/foo"&gt; <record> <id>first</id> <name>john</name> <papers> <paper>john_1</paper> <paper>john_2</paper> </papers> </record> <record> <id>second</id> <...

Can't get nth node in Selenium

I try to write xpath expressions so that my tests won't be broken by small design changes. So instead of the expressions that Selenium IDE generates, I write my own. Here's an issue: //input[@name='question'][7] This expression doesn't work at all. Input nodes named 'question' are spread across the page. They're not siblings. I've t...

Selenium assertText for all text in a table?

I need to assert that each row in table contains a certain text string, either through selenium IDE or a Java test case. What's the best way to do this? Here's my current test: Command assertText Target //table[@id='myTable']//tbody//tr[not(@style)]/td[1] Value myValue I need to test the first column of every row, but this...