xpath

Any way to strip namespace garbage from XML file?

I need to select some nodes from an XML file (AppNamespace.xaml from a Silverlight XAP file, not that it matters), but the file has namespace stuff so XPath doesn't work. I could waste most of a day trial-and-erroring the bondage-and-discipline nightmare of XmlNamespaceManager and end up with hopelessly fragile code that can't tolerate t...

Xpath/C#, getting data from multiple namespaces

So, in the XML below using this code sample, i can successfully grab HomeAddress and Name information for each entry from my XML. What if I also need to grab the ID (drivers license numberxxx) information from each entry? EDIT: Updated XML sample for clarificaiton Code Sample: XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml...

Using a variable in a SQL Server 2005 stored procedure with XQuery

I'm working with the following XML <AEDControl ControlGU="17fed98c-8128-4c6b-9b50-3dbe73889b9d" ControlLabel="Posting Status" TypeGU="6b4d08b1-6340-450c-beae-517b7d84e717" ControlDescription=""> <Elements> <Element ElementGU="2da346d1-2e05-4aa3-9bae-5aa9b3b75d5c" Label="Active" ...

xpath query returning wrong values when using greater and less than???

This query is returning values less than 1000. It should only be returning values between 1000 and 1100. Why is that? //results/Building[ 1 = 1 and (( Vacancy/sqft > 1000 ) and ( Vacancy/sqft < 1100 ) ) ] The query will return the following building, which has vacancies less than 1000 square feet and greater than 1100 square feet: <B...

How to parse html source code with ruby/nokogiri?

I've successfully used ruby (1.8) and nokogiri's css parsing to pull out front facing data from web pages. However I now need to pull out some data from a series of pages where the data is in the "meta" tags in the source code of the page. One of the lines I need is the following: <meta name="geo.position" content="35.667459;139.70625...

Xpath query not working in Objective C using GdataXML

Hi, I am trying to parse an xml using GdataXML I have a query which is not working and I wonder why: <address_component> <long_name>Mars</long_name> <short_name>Mars</short_name> <type>route</type> </address_component> I want to save the long_name where the type is route and I am using this query /*[name() = 'address_compo...

What would be the xpath for this xml

Hi I'm trying to get a variable value (ref within contractRef) in the xml below, but when I use what I assume to be the xpath: /discovery/contractRef[@xmlns='http://schemas.xmlsoap.org/disco/scl/']/@ref it returns nothing. How can I get this variable, what am I missing? Thanks <?xml version="1.0" encoding="utf-8"?> <discovery xmlns:x...

xsl to group nodes between other nodes?

I can't figure out how create xsl to group some nodes between other nodes. Basically, everytime I see a 'SPLIT' I have to end the div and create a new one. The xml looks like this: <data name="a" /> <data name="b" /> <data name="c" /> <data name="SPLIT" /> <data name="d" /> <data name="e" /> <data name="SPLIT" /> <data name="f" /> <da...

Selenium, xpath to match a table row containing multiple elements

I'm trying to find a Selenium/PHP XPath for matching a table row that contains multiple elements (text, and form elements) example: <table class="foo"> <tr> <td>Car</td><td>123</td><td><input type="submit" name="s1" value="go"></td> </tr> </table> This works for a single text element: $this->isElementPresent( "//table/tbody/...

xslt concatenate text from nodes

I have an xml file that looks like this: <args> <sometag value="abc"> <anothertag value="def"> <atag value="blah"> </args> keep in mind that tag names within args could be named anything (I don't know ahead of time) Now i have this xml file stored in a variable called $data which I loaded using a document() call in the xslt styl...

Transforming XML so it can be read with DataSet.ReadXML

I have been given an XML document in a rather strange format and I need to load it into a DataSet, but unsurprisingly I get an error when I try to do so. I can see how I could transform the document into something that would work, but I'm kinda going around in circles with the XSLT stuff... The document looks something like this: <map>...

Merging sequences of elements in XSLT

I've got wads of autogenerated HTML doing stupid things like this: <p>Hey it's <em>italic</em><em>italic</em>!</p> And I'd like to mash that down to: <p>Hey it's <em>italicitalic</em>!</p> My first attempt was along these lines... <xsl:template match="em/preceding::em"> <xsl:value-of select="$OPEN_EM"/> <xsl:apply-templa...

Is there a bug in my XML code or in .NET?

I just ran into an issue where my code was parsing xml fine but once I added in a second node it started to load incorrect data. The real code spans a number of classes and projects but for the sample I've put together the basics of what's causing the issue When the code runs I'd expect the output to be the contents of the second Task n...

xPath help > Find img with alt='My Keyword'

How can I alter this xpath to find if the content contains an img tag with an alt containing my keyword phrase? $xPath->evaluate('count(/html/body//'.$tag.'[contains(.,"'.$keyword.'")])'); ...

Use xPath or Regex?

The two methods below each serve the same purpose: scan the content of the post and determine if at least one img tag has an alt attribute which contains the "keyword" which is being tested for. I'm new to xPath and would prefer to use it depending on how expensive that approach is compared to the regex version... Method #1 uses preg_m...

Determine if a string appears in the first 100 or last 100 text node characters of an html content object

Given a string of text "my search phrase", inside an html content block, how would you determine if the string appears within the first 100 or last 100 non tag-based characters of the document? (Don't count html tags, only text nodes) Example, this would return true... <p>This html text block contains <b>My Search Phrase</b>, because i...

How to define an xpath expression that only retrieves hyphenated elements from the first of two similar divs?

The divs below appear in that order in the HTML I am parsing. //div[contains(@class,'top-container')]//font/text() I'm using the xpath expression above to try to get any data in the first div below in which a hyphen is used to delimit the data: Wednesday - Chess at Higgins Stadium Thursday - Cook-off The problem is I am getting dat...

How to obtain href values from a div using xpath?

I have a div like this: <div class="widget-archive-monthly widget-archive widget"> <h3 class="widget-header">Monthly <a href="http://myblog.com/blogs/my_name/archives.html"&gt;Archives&lt;/a&gt;&lt;/h3&gt; <div class="widget-content"> <ul> <li><a href="http://myblog.com/blogs/my_name/2010/10/"&gt;Octo...

Possible to define an xpath expression that selects <p> elements with hyphenated text but no child HTML tags?

Is it possible to define an xpath expression that selects all <p></p> elements that contain a hyphen in the text but no child html tags. In other words, this would be selected by the xpath expression: <p>Wednesday - Chess at Higgins Stadium</p> But this would be excluded because of the child <b> tags: <p><b>Wednesday</b> - Chess at ...