Re: Matching a node by text data
Brought to you by:
bs_php,
nigelswinson
From: Peter R. <php...@pe...> - 2003-05-09 09:51:11
|
On Thursday 08 May 2003 08:07, Hrotk=F3 G=E1bor wrote: > Hi! > > When i have this xml: > <?xml version=3D"1.0" encoding=3D"UTF-8"?> > <root> > <node> > <tag attrib=3D"1/1">item1/1</tag> > <tag attrib=3D"1/2">item1/2</tag> > <tag attrib=3D"1/3">item1/3</tag> > </node> > <node> > <tag attrib=3D"2/1">item2/1</tag> > <tag attrib=3D"2/2">item2/2</tag> > <tag attrib=3D"2/3">item2/3</tag> > </node> > </root> > > I can use the @ to search for nodes, that has the specified > attribute, like: > > match("/root/node/tag[@attrib=3D'1/2']") > would result: > /root[1]/node[1]/tag[2] > > But how can i search for a node with specified text data, for > example to have the result > /root[1]/node[2]/tag[3] > when i search for the text data: "item2/3"? > For example match("/root/node/tag=3D'item2/3'") or something would be > fine, but now, it isn't working for me. either //*[tag=3D'item2/3'] meaning fetch all nodes with a child element called tag whose content=20 =3D item2/3 or //node[tag=3D'item2/3'] meaning: fetch all nodes called node with a child element called tag=20 whose content =3D item2/3 Check out phpxpath's testbench (testBench/useCases/index.php at=20 wherever you've installed the software) for working out xpath syntax.=20 The syntax is quite simple once you get the hang of it, but it is=20 confusing at first and the official w3c documentation doesn't contain=20 nearly enough examples. |