Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

2 participants