xpath

PHP SimpleXML with XPath

I have an XML structure that looks like this: <?xml version="1.0"?> <survey> <responses>0</responses> <question> <title>Some survey question</title> <answer> <title>Answer 1</title> <responses>0</responses> </answer> <answer> <title>Answer 2</title> <responses>0</responses> </answer> ....

PHP Xpath following-siblings

I'm trying to use xpath to get the contents of a table. The table looks like this <div> <table> <tr class="tableheader"> <td> Stuff </td> </tr> <tr class="indent1"> <td> Contents </td> </tr> <tr class="indent1"> <td> Contents </td> </tr> <tr class="tableheader"> <td> Stuff </td> </tr> <tr class="indent1"> <td> C...

Using var in XPath expression inside c:foreach

Hi all, this is my first question here, so please be gentle ;) I'm trying to loop through a list of items, and use the value of each item in an XPath expression: Works: <c:forEach var="item" items="${items}"> <x:out select="$some_xml//results[@attr1='some_val']/@attr" /> </c:forEach> Fails: <c:forEach v...

cakephp set class with checkboxes

I have an array that looks like: Array ( [63] => 0 [64] => 1 [65] => 1 [66] => 0 ) Is there a way to extract the keys for all the values that are equal to 1 (in this case I just want 64 and 65) using Set::extract or Set::remove or some other method? ...

Is it possible get all context nodes used to evalute xpath result ?

Is it possible get all context nodes used to evalute xpath result ? In below code: test_xml = """ <r> <a/> <a> <b/> </a> <a> <b/> </a> </r> """ test_root = lxml.etree.fromstring(test_xml) res = test_root.xpath("//following-sibling::*[1]/b") for node in res: print test_root.getroottree().getpath(no...

XML: A namespace prefix is claimed to be not declared when it fact it is

We've got a web service that returns a very simple XML. <?xml version="1.0"?> <t:RequestResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://our.website.com/ns/" xmlns:t="http://our.website.com/ns/"&gt; <t:Result>No candy for you today.</t:Result> <t:Success>false</t...

How to loop and display (n) feeds using simpleXML and position()

Hi, I am using simpleXML and I want to loop though the feed to only display 5 shows using the position() method, but have no joy in getting it to work foreach($xml->sortedXPath('TV[position() < 5 and ProgrammeName="MTV"]', 'TransmissionDate', SORT_DESC) as $i => $item) { print "<a href='?v=".$item->ID."&a=false' class='link'>\n"; ...

xpath: contains() for a group of answers

Hi, I'm trying to learn XPath, and I am having trouble with doing a nested search (using contains). Specifically, I was given the following question: There is a list of authors, and a list of books, according to the following dtd: <!ELEMENT db1 (book*, author*)> <!ELEMENT book (title)> <!ATTLIST book bid ID #REQUIRED authors ...

What is wrong in my XPath?

Hi! Here I have the xml: <root> <field ...>offer</field> <field type="ferrari" ...>car</field> <field ...>company</field> <field ...>whatever</field> </root> and I want to know the «type» of the «car» by extracting the element. I thought something like this: /root[field='car']/field (or /root[field='car']) was enoug...

How can I escape a string in classic ASP for use in XPath query?

I have string I'd like to escape for use in an XPath query. In C# I am able to do this using a call to SecurityElement.Escape. Is there an equivalent call in classic ASP? ...

What is the proper XPath query to find the value in this XML document?

Suppose I have this XML document... <root> <str name="My node's attribute">My string's value</str> </root> I want to get the value of the "str" element based on a known value of the elements "name" attribute so I use the following XPath query... str[@name='My node's attribute'] But that doesn't work for me at least not in classic...

Best way to GET the xpath and css selector of a specific element

Looking for the best way to GET the xpath and css selector of a specific element using jQuery or Extjs. To basically select a random element and traverse up the dom and retreive it's unique css selector or xpath. Is there a function that can do this already or does anyone have a custom function that can do this? ...

What is better XPath or Linq2Xml

Hi, What is the "best" way to search in xml? Xpath or Linq2xml. I'm asking this because we need to do a lot of searching in xml. I'm always using XPath (since I've been using this from .NET 1.1). But with the introduction of Linq you can easely use Linq2Sql. Regards, M. ...

selecting current element name in XSLT

I need to output the element name which is being returned after applying the xpath expression for example <xsl:for-each select="//element"> <xsl:value-of select="**{elementname}**"></xsl:value-of> <xsl:text>:</xsl:text> <xsl:value-of select="current()"/> <xsl:value-of /> </xsl:for-each> How can i replace {elem...

XPath: select child elements that do *not* have a specific name

<a> <b/> <c/> <d/> <b/> <e/> </a> How do I select those children of "a" that are not "b"? ...

When running my app with ANT, no XPath implementation can be found.

I wrote an app that uses XPath to query some XML config files. When I run it in eclipse, it works just fine. I also wrote an ant target that runs the application. However, The app gives me a runtime exception when running it from ant. The exception says: XPathFactory#newInstance failed to create an XPathFactory for the default object m...

XPath : select all following siblings until another sibling

Here is an excerpt of my xml : <node/> <node/> <node id="1">content</node> <node/> <node/> <node/> <node id="2">content</node> <node/> <node/> I am positioned in the node[@id='1']. I need an Xpath to match all the <node/> elements until the next not empty node (here node[@id='2']). Edit: the @id attributes are only to explain my ...

Select a specific node in XPath

I have the following XML: <parent> <pet> <data> <birthday/> </data> </pet> <pet> <data> <birthday/> </data> </pet> </parent> And now I want to select the first birthday element via parent//birthday[1] but this returns both birthday elements because bothof them are the first child ...

XPath - Get root node attributes

Hi, I have an XML document with a basic structure like this: <?xml version="1.0" encoding="UTF-8" ?> <records timestamp="1264777862"> <record></record> <record></record> <record></record> <record></record> </records> I've been using the following so far: $doc = new DOMDocument(); $doc->load('myfile.xml'); $xpath = new DOMXPath($doc)...

powershell xml xpath

In Powershell, suppose I have the following xml: <Users> <User Name="Foo"> <Friends> <Friend Name="Bar"/> </Friends> </User> <User Name="Foo2" /> <User Name="Foo3"> <Friends> <Friend Name="Bar"/> </Friends> </User> </Users> How can I get all the users that have a "Bar" as...