xpath

PHP SimpleXML XPath get next parent node

Hi, I've never asked a question here before so please forgive my question if its formatted badly or not specific enough. I am just a dabbler and know very little about PHP and XPath. I have an XML file like this: <catalogue> <item> <reference>A1</reference> <title>My title1</title> </item> <item> <reference>A2</reference> <t...

Grabbing a nodelist from a nodelist c# .net

The following code gives me a nodeList to itterate over: XPathNavigator thisNavigator = thisXmlDoc.CreateNavigator(); XPathNodeIterator dossierNodes = thisNavigator.Select("changedthisname/dossiers/dossier"); I am processing this nodeList, and i need to grab another nodelist out of this list. I am trying to do this by using this code...

Parsing an XML with Xpath in PHP

Consider the following code : $dom = new DOMDocument(); $dom->loadXML($file); $xmlPath = new DOMXPath($dom); $arrNodes = $xmlPath->query('*/item'); foreach($arrNodes as $item){ //missing code } The $file is an xml and each item has a title and a description. How can I display them (title and description)? $file = "<item> <title>t...

Using xPath to find the value of a child node

I am using xPath to do some ETL work from a dictionary lookup file. I need to be able to look for the translation key and return the translated value. For example I need to be able to look for "prioremployment" and have it return "Prior Employment". This will return an array of all the translate nodes (I am using ColdFusion 9): XMLSea...

Use Nokogiri to get all nodes in an element that contain a specific attribute name

Hi, I'd like to use Nokogiri to extract all nodes in an element that contain a specific attribute name. e.g., I'd like to find the 2 nodes that contain the attribute "blah" in the document below. @doc = Nokogiri::HTML::DocumentFragment.parse <<-EOHTML <body> <h1 blah="afadf">Three's Company</h1> <div>A love triangle.</div> <b b...

Where is XPathEvaluator in android web browser?

Hi everyone here. We can use the XPathEvaluator object(in javascript) to do xpath evaluation on Safari,Google Chrome and Safari on Iphone. But on android the browser said that the XPathEvaluator object is undefined. So how can I get a instance of XPathEvaluator object, or is there any other solution to perform xpath evaluation on andro...

How to use XPath with XElement or LINQ?

Consider the following XML: <response> <status_code>200</status_code> <status_txt>OK</status_txt> <data> <url>http://bit.ly/b47LVi&lt;/url&gt; <hash>b47LVi</hash> <global_hash>9EJa3m</global_hash> <long_url>http://www.tumblr.com/docs/en/api#api_write&lt;/long_url&gt; <new_hash>0</new_hash> </data> </response>...

Mechanism to strip specific tags from an XHTML document (but keep their contents)?

I would like a brief and easy way to strip tags from an XHTML document, and believe there has to be something curt enough among all the options like: XSLT, XPath, XQuery, custom C# programming using the .NET XML namespace. I'm open to others. For example, I want to strip all <b> tags from an XHTML document but keep their inner cont...

String functions missing in Xalan 2.7, java.lang.String used instead?!

I am using Xalan 2.7.0 (as bundled with Apache FOP 1.0) and have problems when using string functions. The line <xsl:value-of select="fn:replace('test', 't', '*')"/> results in this exception: javax.xml.transform.TransformerException: java.lang.IllegalArgumentException: argument type mismatch at org.apache.fop.cli.InputHandler.tran...

Using param in XSLT patterns

I am setting a xslt param with PHP, and then calling the transform. I want to use the param value in an XPath expression to grab the proper nodes, but this doesn't seem to be working. I am guess it's possible, I think I am just missing the syntax. Here what I have... PHP: $xslt->setParameter('','month','September'); XSL: <?xml versi...

XPath contains(...)

I have a small problem with Xpath contains with dom4j ... Lets say my XML is <Home> <Addr> <Street>ABC</Street> <Number>5</Number> <Comment>BLAH BLAH BLAH <br/><br/>ABC</Comment> </Addr> </Home> Lets say I want to find all the nodes that have ABC in the text given the root Element... So the xpath tha...

Parsing xml file using xpath and xquery

I have a xml file <?xml version="1.0" encoding="UTF-8"?> <xml> <settings> <title>Calendar for September</title> <subTitle>Calendar for September Calendar for September</subTitle> </settings> <events date="06-09-2010"> <event id="2"> <title>This is My Second Event</title> <description>This is My Second Event </description> </event> <eve...

Explain xpath and xquery in simple terms

I am new to programming. I know what XML is. Can anyone please explain in simple terms what xpath and xquery do Where are they used? ...

How do I retrieve all text in an HTML DOM but exclude SCRIPT and STYLE tags?

I know how to quickly extract text nodes from a DOM: document.evaluate('//text()', document, null, XPathResult.ANY_TYPE, null) But is there an easy way to exclude text from SCRIPT, STYLE, or other tags that are not shown to the user? Something like: '//text()[ parent.name not in ("SCRIPT", "STYLE") ]' Thanks, Mike ...

XPath query: How to refer to the 'current node' (Java/Saxon)

Hello, I'm using a Java application based on Saxon for the XPath parser. Please consider the following: <import> <record ref="abc"> <id>123</id> <data>Value<data> </record> <record ref="def"> <parent>123</parent> <data>Value2</data> </record> </import> My use case is, I'm looping through the...

HtmlUnit and XPath: DOMNode.getByXPath only works on HtmlPage?

I'm trying to parse a page with links to articles whose important content looks like this: <div class="article"> <h1 style="float: none;"><a href="performing-arts">Performing Arts</a></h1> <a href="/performing-arts/EIF-theatre-review-Sin-Sangre.6517348.jp"> <span class="mth3"> <span id="wctlMiniTemplate1_ctl00_ctl00_ctl01_...

SQL: Query a List within a List XML

I'm trying to query some XML in SQL Server but am having difficulties: Here is some sample XML: <BaseReport> <Parties> <Party> <SubjectType> <ListItem Name="SubjectType1Name" /> <ListItem Name="SubjectType2Name" /> </SubjectType> </Party> <Party> <SubjectType> <ListItem Name="SubjectType...

How to select the grandparent of a node using xslt

I'm in a situation where I can only test for the child node, but I have to apply tags to the grandparent of this child node. I've tried using: <xsl:call-template name="grandparent" select="parent::parent::node()"/> and: <xsl:call-template name="grandparent" select="ancestor::node [@nameofgrandparentnode]"/> But neither works. Th...

How to select specified node within Xpath node sets by index with Selenium?

I'm writing a Selenium testcase. And here's the xpath expression I use to match all 'Modify' buttons within a data table. //img[@title='Modify'] My question is, how can I visit the matched node sets by index? I've tried with //img[@title='Modify'][i] and //img[@title='Modify' and position() = i] But neither works.. I also tri...

How to travese back to the parent node in the XML file by using Xpath(using XSLT) query?

Let us have a xml tree of depth N. I have traveresd the last node means i am at last note. Now i wanted to go back to some level up (say at N-3) in the xml tree from that last node. Please let me know the syntax for the XPATH query so that i can reached at intended node in the xml tree. ...