xpath

Searching and replacing XML Data

I need to search for certain nodes in an XML document, modify the InnerXML property of those nodes, and then write the changes out to the file. I can search the nodes find using XPathDocument, XPathNavigator, etc... but any sort of writing using these classes doesn't seem to be supported. Is there a way to pull a node out using the XPa...

C# XmlDocument SelectNodes

I have an xml document with a root element, two child elements, 'diagnostic' and 'results'. The 'results' element then has an arbitrary number of elements with the name 'result' When this is loaded into an XmlDocument it is easy to navigate the structure and see that this is exactly how things operate. I can write a recursive function...

xPath strange behaviour - selecting ALL elements even if [1] set.

Hello, today I stumbled upon a very interesting case (at least for me). I am messing around with Selenium and xPath and tried to get some elements, but got a strange behaviour: <div class="resultcontainer"> <div class="info"> <div class="title"> <a> some text </a> </div> </div> </div> <div cla...

How to express a string containing both apostrophes and quotes in XPath?

I'll spare you the details because they would be needlessly confusing. Long story short, I'm using XSLT 1.0 to generate XSL documents, I'm trying to compare a variable to a literal string, and that string may contain quotes and apostrophes. For the sake of simplicity, let's say that this literal is composed of two characters: a quote fo...

regular expressions and xpath query

Hello I have the following code <?php $doc = new DOMDocument; $doc->loadhtml('<html> <head> <title>bar , this is an example</title> </head> <body> <h1>latest news</h1> ...

JavaScript - quickest way to extract document meta fields

I need to extract the document's "description" meta tag. The default way would be to use document.getElementsByTagName('META') and then iterate through the array - as found in: http://www.rgagnon.com/jsdetails/js-0070.html But I'm wondering if there's no other quicker, "one line of code" approach. I'm not familiar with xPath - but mayb...

Select the same attribute in XPath and return result without repetition

I have an XML document like this: <wii> <game> <type genre="arcade" /> <type genre="sport" /> </game> <game> <type genre="platform" /> <type genre="arcade" /> </game> </wii> How to list all genres without repetition using only XPath? Thanks. ...

XPath - Select first element after some other element

I'm fairly new to XPath, been fiddling around with it for a few hours now, so i'm not entirely sure if you can even do something like the following with it. Okay, here's the scenario: I want to find a link from a page. That link is only recodnizable by it's text value, ie. the text between <a> tags (<a href="#">this link<a>). So far i'...

sum of alternate numbers (XML/XSL)

Need to add alternate digits in a number receiving from XML file using XSLT, for instance If I am receiving a 123456789, I need to calculate alternate digit sum from right most using XSLT function, can i have any suggestions on this ? Thanks, Laxmikanth.S ...

Is there a jquery selector extractor akin to the xpather firefox extension?

Firefox has an Xpather extension that allows one to inspect html and extract xpaths. Is there something similar to extract jQuery selectors from html? ...

How can I force an XSLT result tree to serialize with a particular default namespace?

I'm trying to strip the namespace qualifiers from a document, while retaining the document namespace as the default: <foo:doc xmlns:foo='somenamespace'> <foo:bar /> </foo:doc> To <doc xmlns='somenamespace'> <bar/> </doc> (I know, this is meaningless, but our client doesn't get XML and uses string comparisons to find informa...

Joining 2 XPath Queries

I'm having a hard time with XPath here.. Given the following XPath queries: $xpath->query('//input[@name="' . $field . '"]'); $xpath->query('//select[@name="' . $field . '"]'); Is is possible to combine them into one single query? I want to get the value of the field, however I don't know if the field with be a input, select, textarea...

How do I run XPath queries in QT?

How do I run an XPath query in QT? I need to sort out certain tags with specific values in a certain attribute. The QXmlQuery documentation is anything but legible. The schema I'm parsing is the Rhythmbox DB format: <rhythmdb version="1.6"> <entry type="ignore"> <title></title> <genre></genre> <artist></artist> <al...

convert name value pairs to xml

given a bunch of data in the form of name-value pairs how can i construct that into xml? eg: Title : Mr Name : John Surname : Doe as valid xml sililar to: <Data> <Title>Mr</Title> <Name >John</Name > <Surname >Doe</Surname > </Data> ...

DOMDocument & XPath - HTML Tag of each Node

Given the following PHP code using DOMDocument: $inputs = $xpath->query('//input | //select | //textarea', $form); if ($inputs->length > 0) { for ($j = 0; $j < $inputs->length; $j++) { $input = $inputs->item($j); $input->getAttribute('name'); // Returns the Attribute $input->getTag(); // How can I get the input,...

Most elegant way to query XML string using XPath

I'm wondering what the most elegant way is in C# to query a STRING that is valid xml using XPath? Currently, I am doing this (using LINQ): var el = XElement.Parse(xmlString); var h2 = el.XPathSelectElement("//h2"); ...

Validate XPath expression

I would like to validate a user-provided XPath query to ensure that it is syntactically correct. Does it make sense to "validate" an XPath query without an XML document? How can i achieve such a thing in libxml? ...

Selecting the two elements with the lowest attribute values and merging them into one element in the output

Using xslt/xpath, I need to be able to select the two elements which have the lowest attribute value and merge them, in a way. Lets say for example I have: <root> <integer val="14"/> <integer val="7"/> <integer val="2"/> <integer val="1"/> <integer val="4"/> <integer val="8"/> </root> I want to select the two lowest values (1 a...

Is there an XPath equivilent for Linq to XML?

I have been using Linq to XML for a few hours and while it seems lovely and powerful when it comes to loops and complex selections, it doesn't seem so good for situations where I just want to select a single node value which XPath seems to be good at. I may be missing something obvious here but is there a way to use XPath and Linq to XM...

Combining Conditions in XPath and XSLT

I am trying to build an XPath select just the 'Phone' number from the following: <element identifier="ContactPoint" version="Local"> <qualifier name="Phone" type="refining"/> 01234 567890 </element> <element identifier="ContactPoint" version="Local"> <qualifier name="Email" type="refining"/> [email protected] </element...