Add support for tag="{*}name" in _Element.iter() and friends. #66

Merged
merged 2 commits into from Aug 13, 2012

Conversation

Projects
None yet
2 participants
Contributor

SimonSapin commented Aug 11, 2012

Such methods now have all combinations of wilcards to implement
CSS selectors NS|E, |E, *|E, NS|*, |*, and *|*

Internally the meaning of the qname.href struct field was changed:

  • The NULL pointer is a wildcard, matches any namespace
  • The empty Python byte-string matches elements without a namespace
  • Other Python byte-strings are namespace URIs, matching elements in
    the same namespace.

qname.c_name is uchanged (NULL for a wildcard, a C string for a
given local name.)

@SimonSapin SimonSapin Add support for tag="{*}name" in _Element.iter() and friends.
Such methods now have all combinations of wilcards to implement
CSS selectors NS|E, |E, *|E, NS|*, |*, and *|*

Internally the meaning of the qname.href struct field was changed:

* The NULL pointer is a wildcard, matches any namespace
* The empty Python byte-string matches elements without a namespace
* Other Python byte-strings are namespace URIs, matching elements in
  the same namespace.

qname.c_name is uchanged (NULL for a wildcard, a C string for a
given local name.)
4e1e685

@SimonSapin SimonSapin and 1 other commented on an outdated diff Aug 11, 2012

@@ -8,6 +8,20 @@ lxml changelog
Features added
--------------
+
+* The ``.iter()`` method of elements now accepts ``tag`` arguments like
+ ``"{*}name"`` to search for elements with a given local name in any
+ namespace. With this addition, all combinations of wildcards now work
+ as expected:
+ ``"{ns}name"``, ``"{}name"``, ``"{*}name"``, ``"{ns}*"``, ``"{}*"``
+ and ``"{*}*"``. Note that ``"name"`` is equivalent to ``"{}name"``,
+ but ``"*"`` is ``"{*}*"``.
+ The same change applies to the ``.getiterator()``, ``.itersiblings()``,
+ ``.iterancestors()``, ``.iterdescendants()``, ``.iterchildren()``
+ and ``.itertext()`` methods as well as the ``strip_attributes()``,
+ ``strip_elements()`` and ``strip_tags()`` functions.
@SimonSapin

SimonSapin Aug 11, 2012

Contributor

Apparently some stuff in iterpase.pxi also uses _MultiTagMatcher, but I’m not sure how that translates into the public API.

@scoder

scoder Aug 12, 2012

Owner

You can pass a tag name into iterparse(), which then behaves essentially like .iter(tag), but during parsing. So it's affected as well.

@SimonSapin

SimonSapin Aug 12, 2012

Contributor

Noted.

@scoder scoder merged commit 87d6821 into lxml:master Aug 13, 2012

Owner

scoder commented Aug 13, 2012

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment