xpath

What's wrong with my XPath/XML?

I'm trying a very basic XPath on this xml, and it doesn't find anything. I'm trying both .NET and this website, and XPaths such as "//PropertyGroup", "/PropertyGroup" and "//MSBuildCommunityTasksPath" are simply not working for me (they compiled but return zero results). ...

Can XPath return only nodes that have a child of X?

Is it possible to use XPath to select only the nodes that have a particular child elements? For example, from this XML I only want the elements in pets that have a child of 'bar'. So the resulting dataset would contain the lizard and pig elements. <pets> <cat> <foo>don't care about this</foo> </cat> <dog> <foo>not this one either...

Select Element in a Namespace with XPath

I want to select the topmost element in a document that has a given namespace (prefix). More specifically: I have XML documents that either start with /html/body (in the XHTML namespace) or with one of several elements in a particular namespace. I effectively want to strip out /html/body and just return the body contents OR the entire r...

Is there a good online introduction/overview to XPath 2.0?

Basically I want something I can refer people to that covers the main differences to XPath 1.0 ('for' and 'if' statements and the use of sequences), in a sort of 'bluffers guide' or cheatsheet format. ...

PHP simplexml problem

I have the following XML structure: <?xml version="1.0" ?> <course xml:lang="nl"> <body> <item id="787900813228567" view="12000" title="0x|Beschrijving" engtitle="0x|Description"><![CDATA[Dit college leert studenten hoe ze een onderzoek kunn$ <item id="5453116633894965" view="12000" title="0x|Onderwijsvorm" engtitle="0x|Method...

How to retrieve namespaces in XML files using Xpath

Hello, I have an XML file that starts like this: <Elements name="Entities" xmlns="XS-GenerationToolElements"> I'll have to open a lot of these files. Each of these have a different namespace but will only have one namespace at a time (I'll never find two namespaces defined in one xml file). Using XPath I'd like to have an automatic ...

How do you identify duplicate elements in an XPath 2.0 sequence ?

I have an XPath expression which provides me a sequence of values like the one below: 1 2 2 3 4 5 5 6 7 It is easy to convert this to a set of unique values "1 2 3 4 5 6 7" using the distinct-values function. However, what I want to extract is the list of duplicate values = "2 5". I can't think of an easy way to do this. Can anyone hel...

How do you parse a HTML string for image tags to get at the SRC information?

Possibly a lame question. But I've yet to find an answer to it. Currently I use .Net WebBrowser.Document.Images() to do this. It requires the Webrowser to load the document. Its messy and takes up resources. According to this Question Xpath is better than a regex at this. Anyone know how to do this in C#? Thanks ...

Yahoo GeoPlanet & XPathNavigator C#

I am returning XML data from the Yahoo GeoPlanet web service using HttpWebRequest. I am loading the XML using XPathDocument doc = new XPathDocument(HttpWebResponse.GetResponseStream()) Next comes XPathNavigator nav = doc.CreateNavigator(); If I do nav.Select("places"); or nav.Select("/places"); or nav.Select("//places"); Nothing g...

Pulling both the text and attribute of a given node using Xpath

I'm parsing XML results from an API call using PHP and xpath. $dom = new DOMDocument(); $dom->loadXML($response->getBody()); $xpath = new DOMXPath($dom); $xpath->registerNamespace("a", "http://www.example.com"); $hrefs = $xpath->query('//a:Books/text()', $dom); for ($i = 0; $i < $hrefs->length; $i++) { $arrBookTitle[$i]...

Can XPath do a foreign key lookup across two subtrees of an XML?

Say I have the following XML... <root> <base> <tent key="1" color="red"/> <tent key="2" color="yellow"/> <tent key="3" color="blue"/> </base> <bucket> <tent key="1"/> <tent key="3"/> </bucket> </root> ...what would the XPath be that returns that the "bucket" contains "red" and "blue"? ...

xpath query searching text

Give the following XML structure <html> <body> <div> <span>Test: Text2</span> </div> <div> <span>Test: Text3</span> </div> <div> <span>Test: Text5</span> </div> </body> </html> What is the best xpath query to locate any span with text that starts with Test? ...

How do I resolve the error "Expression must evaluate to a node-set" when checking for the existence of a node?

I'm attempting to check for the existence of a node using the following .NET code: xmlDocument.SelectSingleNode(String.Format("//ErrorTable/ProjectName/text()='{0}'", projectName)); This always raises XPathException: Expression must evaluate to a node-set. Why am I getting this error and how can I resolve it? Thank you. ...

.NET : How do you remove a specific node from an XMLDocument using XPATH?

Using C# How do you remove a specific node from an XMLDocument using XPATH? ...

How can I delete a specific node within a XML file by using vbscript

Hey there! I am having the problem that I cannot select a specific XML node which needs to be deleted. I have already tried to select the node by using the XPath which works fine for some XML files but I cannot figure out the correct XPath for a node in a more complex file. Does anybody know a freeware tool which can load a XML file so...

Problem selecting HTML elements with xpath in Internet Explorer

I'm trying to select a specific HTML element in a document, for firefox i just use: xpathobj = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); which works fine. However when i try the IE equivilent: xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load(document); xmlDoc.set...

What is more efficient for parsing Xml, XPath with XmlDocuments, XSLT or Linq?

I have parsed Xml using both of the following two methods... Parsing the XmlDocument using the object model and XPath queries. XSL/T But I have never used... The Linq Xml object model that was new to .Net 3.5 Can anyone tell me the comparative effeciantly between the three alternatives? I realise that the particular usage would ...

Cross-browser XPath implementation in JavaScript

I'm looking for a XPath library to query over XML documents in FF, IE, Opera and Safari... and couldn't find one. Have you seen any? ...

how to select an element within a specific namespace?

I'm having trouble selecting elements that are part of an specific namespace. My xpath expression works in XMLSpy but fails when using the Xalan libraries.. <item> <media:content attrb="xyz"> <dcterms:valid>VALUE</dcterms:valid> </media:content> </item> My expression ./item/media:content/dcterms:valid. I've already added b...

Cleaning/sanitizing xpath attributes

I need to dynamically construct an XPath query for an element attribute, where the attribute value is provided by the user. I'm unsure how to go about cleaning or sanitizing this value to prevent the XPath equivalent of a SQL injection attack. For example (in PHP): <?php function xPathQuery($attr) { $xml = simplexml_load_file('exa...