Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inherit XMLNS during encoding like we did in v3 #88

Merged
merged 1 commit into from
Jan 26, 2025

Conversation

veewee
Copy link
Owner

@veewee veewee commented Jan 24, 2025

Q A
Type bug
BC Break no
Fixed issues #87

Summary

Fixes #87

This PR makes sure encoding / decoding inherits default XMLNS declarations, just like v3 did.

$data = xml_decode(
    $xml = <<<XML
    <foo xmlns="uri://bar">
        <x:a xmlns:x="uri://x">
            <x:b xmlns="uri://aa">
                <bar>bar</bar>
            </x:b>
        </x:a>
    </foo>
    XML
);

echo $xml;
var_dump($data);
echo xml_encode($data, utf8(), pretty_print());
<foo xmlns="uri://bar">
    <x:a xmlns:x="uri://x">
        <x:b xmlns="uri://aa">
            <bar>bar</bar>
        </x:b>
    </x:a>
</foo>

array(1) {
  ["foo"]=>
  array(2) {
    ["@namespaces"]=>
    array(1) {
      [""]=>
      string(9) "uri://bar"
    }
    ["x:a"]=>
    array(2) {
      ["@namespaces"]=>
      array(1) {
        ["x"]=>
        string(7) "uri://x"
      }
      ["x:b"]=>
      array(2) {
        ["@namespaces"]=>
        array(1) {
          [""]=>
          string(8) "uri://aa"
        }
        ["bar"]=>
        string(3) "bar"
      }
    }
  }
}

<?xml version="1.0" encoding="UTF-8"?>
<foo xmlns="uri://bar">
  <x:a xmlns:x="uri://x">
    <x:b xmlns="uri://aa">
      <bar>bar</bar>
    </x:b>
  </x:a>
</foo>

@veewee veewee force-pushed the xmlns-inheriting-encoding branch from 7bb8905 to c7b1171 Compare January 26, 2025 15:09
@veewee veewee merged commit a732fcd into 4.x Jan 26, 2025
10 checks passed
@veewee veewee deleted the xmlns-inheriting-encoding branch January 26, 2025 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extra empty xmlns attribute for encoded document
1 participant