|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits              [2008-03-28 14:08 UTC] rrichards@php.net
 | |||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 00:00:01 2025 UTC | 
Description: ------------ I would like to query my XML file with XPath using starts-with. This is an example of my XML file: <?xml version="1.0" encoding="utf-8"?> <graphml> <graph id="G" edgedefault="directed"> <node id="4"> <data key="label">name</data> <data key="value">Alanine</data> <data key="node_path">moldb.molecule.name</data> </node> </graph> </graphml> I want to query to the node having the "node_path" attribute beginning by "moldb". But this didn't work. After trying many cases, I think it came from the XML structure that has more than one "data" nodes. If there is only one "data" node, it worked. Reproduce code: --------------- Here is my code: $doc = new DomDocument(); // document to be explored if (!$doc->load("ex.xml")) { return; // invalid file } $xpath = new DOMXPath($doc); // to search for the nodes we want $data = 'moldb'; $query = "/graphml/graph/node[starts-with(data,'$data')]"; $query = "/graphml/graph/node[data[@key='node_path'] and starts-with(data,'$data')]"; $entries = $xpath->evaluate($query); echo $entries->length."\n"; Expected result: ---------------- When executing this script, it should print: 1 Actual result: -------------- The obtained result is: 0