xpath

How to parse an iCal Rss node

Hi There, Can someone help me with a line of code to access an iCal node from an RSS feed? Specifically i want to access the xCal:x-calconnect-venue-name node. My parent node is 'item', so the path is: item/xCal:x-calconnect-venue/xCal:adr/xCal:x-calconnect-venue-name How can i use parent.SelectChildNode() to access the value of tha...

Weird XPath behavior in libxml2

I have this XML tree that looks like this (I've changed the tag names but if you're really clever you may figure out what I'm actually doing.) <ListOfThings> <Thing foo:action="add"> <Bar>doStuff --slowly</Bar> <Index>1</Index> </Thing> <Thing foo:action="add"> <Bar>ping yourMother.net</Bar> <Index>2</In...

Xpath - How to get all the attribute names and values of an element

I am using xpath in java. I want to get all the attributes (name & Value) of an element. I found the query to get the attribute values of an element, now I want to get attribute names alone or names and values in single query. <Element1 ID="a123" attr1="value1" attr2="value2" attr3="value3" attr4="value4" attr5="value5" /> Here using ...

What is the difference between name() and local-name() ?

I don't really understand the difference between the XPath functions name and local-name. Could you give an example of a situation where they would differ? Edit Given this example: <?xml version="1.0" ?> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head></head> </html> I get the same result with these two ...

Help in XPath expression

I have an XML document which contains nodes like following:- <a class="custom">test</a> <a class="xyz"></a> I was tryng to get the nodes for which class is NOT "Custom" and I wrote an expression like following:- XmlNodeList nodeList = document.SelectNodes("//*[self::A[@class!='custom'] or self::a[@class!='custom']]"); Now, I want ...

Get all attribute values of given tag with Html Agility Pack

Hello. I want to get all values of 'id' attribute of 'span' tag with html agility pack. But instead of attributes I got tags themself. Here's the code private static IEnumerable<string> GetAllID() { HtmlDocument sourceDocument = new HtmlDocument(); sourceDocument.Load(FileName); var n...

Find all <a>s to who's href points to an image with XPath 1.0

First, I can assume that all urls that end with jpeg, jpg, bmp, png or gif are images, and others aren't. I thought of, and tried two solutions: Matching the regular expression .(jpe?g|bmp|png|gif)$ Using ends-with to check each separately But, it appears that neither of these exist in XPath 1.0, or at least, they don't exist in Fir...

In XPath how to select the element content

Hi all, Is there a way of writing an XPath expression to select the content of the element. e.g. <Element>xxx</Element> Assuming I can write XPath (/Element) to get Element how do I tweak the XPath to get xxxx returned rather than the Element wrapper? EDIT/ANSWER To do this in dom4j world use the Element.valueOf(String xpathExpres...

Sorted exsl:node-set. Return node by it position.

Good afternoon, gentlemen. Help me solve a very simple task. I have a set of nodes <menuList> <mode name="aasdf"/> <mode name="vfssdd"/> <mode name="aswer"/> <mode name="ddffe"/> <mode name="ffrthjhj"/> <mode name="dfdf"/> <mode name="vbdg"/> <mode name="wewer"/> <mode name="mkiiu"/> <mode name="yhtyh"/> and so o...

Remove Empty Attributes from XML

Hi, I have a buggy xml that contains empty attributes and I have a parser that coughs on empty attributes. I have no control over the generation of the xml nor over the parser that coughs on empty attrs. So what I want to do is a pre-processing step that simply removes all empty attributes. I have managed to find the empty attributes,...

Copy data from one table Column another table Xml Node with many to one relation

I have two tables like this declare @Habits_new table(ID int,Habits xml default '<habits></habits>') declare @Habits_OLD table (ID varchar(50), Habit varchar(50)) Having data Like this INSERT @Habits_new values(1,'<habits><habit>Drink</habit></habits>') INSERT @Habits_new values(2,'<habits><habit>snor</habit></habits>') INSERT @Habi...

Xpath and parameters

I am relatively new to XSL and I think this is a basic question. So I better get my apologies in early! Basically, I would like to use a value-of function. This will be in a template and I would like to pass part of the xpath as a parameter. <xsl:variable name="TEST_VAR">"h:elementA/elementB"</xsl:variable> ... and then use the varia...

Interpret a rule applying multiple xpath queries on multiple XML documents

Hi, I need to build a component which would take a few XML documents in input and check the following kind of rules: XML1:/bookstore/book[price>35.00] != null and (XML2:/city/name = 'Montreal' or XML3://customer[@language] contains 'en') Basically my component should be able to: substitute the XML tokens with the correspondin...

PHP parsing XML file with and without namespaces

I need to get a XML File into a Database. Thats not the problem. Cant read it, parse it and create some Objects to map to the DB. Problem is, that sometimes the XML File can contain namespaces and sometimes not. Furtermore sometimes there is no namespace defined at all. So what i first got was something like this: <?xml version="1.0" e...

Select all links from a Html table using XPath (and HtmlAgilityPack)

What I am trying to achieve is to extract all links with a href attribute that starts with http://, https:// or /. These links lie within a table (tbody > tr > td etc) with a certain class. I thought I could specify just the the a element without the whole path to it but it does not seem to work. I get a NullReferenceException at the lin...

Can I build this XPath query dynamically in XSLT?

I have a document that looks something like <root> <element> <subelement1 /> <subelement2 /> </element> <element> <subelement2 /> <subelement1 /> </element> </root> In my XSLT sheet in the context of /element[2]/[someNode] I want to get a number that represents the distance of /element[1...

Parse RDF XML file to get all rdf:about values

I am using php's simple xml and xpath to parse an rdf xml file and am struggling to get a list of all the rdf:about values. Any advice? ...

XPATH - Select all child nodes with a specific attribute

Hi, what would be the xpath for the following: Find all child nodes with a specific attibute value but starting from a node with a specific attribute value. This is kind of related to a question I posted earlier about parsing and rdf xml file - I thought I had solved it but not quite yet. For example I am trying to parse and grab all ...

Selecting an element based on text and attribute of its sibling, using Xpath

Looking at the document, the goal is to select the second cell from the second row, in the first table. I've created the following expression: //row/td[2]/text()[td[@class="identifier"]/span[text()="identifier"]] but it does not return any rows. Unfortunately I do not see what's wrong. To me, it looks alright. The expression shoul...

pass object from JS to PHP and back

This is something that I don't think can't be done, or can't be done easy. Think of this, You have an button inside a div in HTML, when you click it, you call a php function via AJAX, I would like to send the element that start the click event(or any element as a parameter) to PHP and BACK to JS again, in a way like serialize() in PHP, ...