add tag-named-with-attr to xml.traversal

db4
Samuel Tardieu 2011-12-14 23:05:57 +01:00 committed by Joe Groff
parent 50dced41d4
commit 46a00c4ce2
3 changed files with 16 additions and 2 deletions

View File

@ -67,7 +67,16 @@ HELP: tag-named
{ "name/string" "an XML name or string representing the name" }
{ "matching-tag" tag } }
{ $description "Finds the first tag with matching name which is the direct child of the given tag." }
{ $see-also deep-tags-named deep-tag-named tags-named } ;
{ $see-also deep-tags-named deep-tag-named tag-named-with-attr tags-named } ;
HELP: tag-named-with-attr
{ $values { "tag" "an XML tag or document" }
{ "tag-name" "an XML name or string representing the name" }
{ "attr-value" "a string representing the attribute value" }
{ "attr-name" "a string representing the attribute name" }
{ "matching-tag" tag } }
{ $description "Finds the first tag with matching name with the corresponding attribute name and value which is the direct child of the given tag." }
{ $see-also tag-named } ;
HELP: tags-named
{ $values { "tag" "an XML tag or document" }

View File

@ -1,6 +1,6 @@
! Copyright (C) 2005, 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: xml xml.traversal tools.test xml.data sequences arrays ;
USING: xml xml.traversal tools.test xml.data sequences arrays kernel ;
IN: xml.traversal.tests
[ "bar" ] [ "<foo>bar</foo>" string>xml children>string ] unit-test
@ -19,3 +19,5 @@ IN: xml.traversal.tests
[ { "blah" } ] [ "<foo><bar attr='blah'/></foo>" string>xml "blah" "attr" tags-with-attr [ "attr" attr ] map ] unit-test
[ { "blah" } ] [ "bar" { { "attr" "blah" } } f <tag> 1array "blah" "attr" tags-with-attr [ "attr" attr ] map ] unit-test
[ { "http://hub.example.com" "http://alt.example.com" } ] [ "<head><link rel='alternate' href='http://alt.example.com'/><link rel='hub' href='http://hub.example.com'/></head>" string>xml-chunk "head" tag-named [ "link" "hub" "rel" tag-named-with-attr ] [ "link" "alternate" "rel" tag-named-with-attr ] bi [ "href" attr ] bi@ 2array ] unit-test

View File

@ -49,6 +49,9 @@ PRIVATE>
: tag-with-attr ( tag attr-value attr-name -- matching-tag )
assure-name '[ _ _ tag-with-attr? ] find nip ;
: tag-named-with-attr ( tag tag-name attr-value attr-name -- matching-tag )
[ tags-named ] 2dip '[ _ _ tag-with-attr? ] find nip ;
: tags-with-attr ( tag attr-value attr-name -- tags-seq )
assure-name '[ _ _ tag-with-attr? ] { } filter-as ;