]> gitweb.factorcode.org Git - factor.git/commitdiff
add tag-named-with-attr to xml.traversal
authorSamuel Tardieu <sam@rfc1149.net>
Wed, 14 Dec 2011 22:05:57 +0000 (23:05 +0100)
committerJoe Groff <arcata@gmail.com>
Sat, 17 Dec 2011 00:07:01 +0000 (16:07 -0800)
basis/xml/traversal/traversal-docs.factor
basis/xml/traversal/traversal-tests.factor
basis/xml/traversal/traversal.factor

index d8032d99fc6975b9cd905d90203ddd83f42b6320..39c3951043f11357de4b0f4c0ce5bf5a61a33e72 100644 (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" }
index c7e8c0a4aebf8ca2a7decf2a44dd450f2b15d3ee..de04830e4a6bbaa87660a71e6611c72f9b0d8f92 100644 (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
index ce3555fe817cc544b521d2f27c72d67f831a633d..f5b1baf6f18f9254c47264abf6162c6cc57cbb33 100644 (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 ;