Re: xpath: how to select node based on attribute value only?

Jan Wielemaker <[email protected]>
Newsgroups gmane.comp.ai.prolog.swi
Message-ID <[email protected]>
On 10/18/2013 01:00 AM, John Stewart wrote:
> Hi,
>
> I'm trying to iterate through all nodes that have some attribute, say "id". �I can say:
>
> ?- load_my_thing("foo.xml", XML),xpath(XML, //'*'(@id), P).
>
>
> And I get back all the id attributes. �And I can ask for the element content for a known value for a known element name:
>
> ?- load_my_thing("foo.xml", XML),�xpath(XML, //h2(@id='x-ck12-TGVzc29uIFJldmlldyBRdWVzdGlvbnM.-r07'), P).
>
> ...
> P = element(h2, [id='x-ck12-TGVzc29uIFJldmlldyBRdWVzdGlvbnM.-r07'], [' � Lesson Review Questions\n �'])
>
>
> But I haven't worked out how to find the element with known attribute but not known element name:
>
> ?- load_my_thing("foo.xml", XML), xpath(XML, //'*'(@id='x-ck12-TGVzc29uIFJldmlldyBRdWVzdGlvbnM.-r07'), P).
>
> false.
>
> Any help appreciated. �Thanks.

Works fine here.  Are you using an old version?  Tested on current 
stable and devel version.  Note that you do have to load the library
explicitly to get the correct operator definitions.

	Cheers --- Jan

_______________________________________________
SWI-Prolog mailing list
[email protected]
https://lists.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.