You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Add Namespace Support to XMLProcessor
This PR upgrades `XMLProcessor` to fully support [[XML Namespaces
1.1](https://www.w3.org/TR/xml-names11/)](https://www.w3.org/TR/xml-names11/).
Tags and attributes are now consistently interpreted according to their
declared namespaces, fixing compatibility with WordPress WXR files and
EPUB metadata.
New methods signatures:
```php
public function next_tag( $query_or_namespace = null, $local_name_maybe = null );
public function get_tag_local_name();
public function get_tag_namespace();
public function get_attribute( $namespace, $local_name );
public function get_attribute_names_with_prefix( $full_namespace_prefix, $local_name_prefix );
public function set_attribute( $namespace, $local_name, $value );
```
Usage comparison:
```php
// Before
$processor->next_tag( 'wp:content' );
$processor->get_attribute( 'wp:post-type' );
// After
$processor->next_tag( 'http://wordpress.org/export/1.2/', 'content' );
// or
$processor->next_tag( [ 'http://wordpress.org/export/1.2/', 'content' ] );
$processor->next_tag( [ '*', 'content' ] );
$processor->get_attribute( 'http://wordpress.org/export/1.2/', 'post-type' );
```
## Rationale
The old parser treated tag and attribute names as opaque strings
(`wp:postmeta`, `wp:tag`, etc.), ignoring that these were syntactic
sugar for `{namespace}local-name`. This made it impossible to reliably
parse WXR files, which may use different namespace URIs for the same
`wp:` prefix.
## Implementation Details
* `$stack_of_open_elements` tracks the hierarchy of `XMLElement` frames
and the namespaces they define and remove.
* `set_attribute($ns, $attr, $value)` and `get_attribute($ns, $attr)`
accept the full namespace string as their first argument to force the
developer to take it into consideration.
* `next_tag()` and `matches_breadcrumbs()` accept two-tuples
`{$namespace, $local_tag_name}` instead of string-based tag names. Tag
names are still accepted. `*` wildcards are supported, too.
* `get_breadcrumbs()` return an array of two-tuples `{$namespace,
$local_tag_name}`, e.g. `[['', 'root'], ['http://wp.org/export/1.2/',
'post']]`
## Testing instructions
Confirm most of the CI tests pass (aside of the flaky network-related
ones)
0 commit comments