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

XML Writer fails on XML content with attributes #131

Open
TravisCarden opened this issue Oct 17, 2020 · 1 comment · May be fixed by #150
Open

XML Writer fails on XML content with attributes #131

TravisCarden opened this issue Oct 17, 2020 · 1 comment · May be fixed by #150
Labels

Comments

@TravisCarden
Copy link

TravisCarden commented Oct 17, 2020

The XML writer doesn't work on XML that contains attributes. I discovered this trying to modify my phpunit.xml.

Here's a passing test case with one of the project's own mocks:

$raw = <<<RAW
<?xml version="1.0" encoding="UTF-8"?>
<config>
    <application>
        <name>configuration</name>
        <secret>s3cr3t</secret>
    </application>
    <host>localhost</host>
    <port>80</port>
    <servers>
        <server1>host1</server1>
        <server2>host2</server2>
        <server3>host3</server3>
    </servers>
</config>
RAW;
$config = new \Noodlehaus\Config($raw, new \Noodlehaus\Parser\Xml(), TRUE);
$xml = $config->toString(new \Noodlehaus\Writer\Xml(), TRUE);
print $xml;

Result:

<?xml version="1.0"?>
<config>
  <application>
    <name>configuration</name>
    <secret>s3cr3t</secret>
  </application>
  <host>localhost</host>
  <port>80</port>
  <servers>
    <server1>host1</server1>
    <server2>host2</server2>
    <server3>host3</server3>
  </servers>
</config>

Add an attribute to any element in the XML, and it will fail:

$raw = <<<RAW
<?xml version="1.0" encoding="UTF-8"?>
<config test="example">
    <application>
        <name>configuration</name>
        <secret>s3cr3t</secret>
    </application>
    <host>localhost</host>
    <port>80</port>
    <servers>
        <server1>host1</server1>
        <server2>host2</server2>
        <server3>host3</server3>
    </servers>
</config>
RAW;
$config = new \Noodlehaus\Config($raw, new \Noodlehaus\Parser\Xml(), TRUE);
$xml = $config->toString(new \Noodlehaus\Writer\Xml(), TRUE);
var_dump($xml);

Result:

<?xml version="1.0"?>
@DavidePastore DavidePastore added this to the Future release milestone Mar 26, 2022
@DavidePastore
Copy link
Collaborator

Hi, @TravisCarden. Thanks for opening this issue! I'll work on a fix.

@DavidePastore DavidePastore linked a pull request Apr 3, 2022 that will close this issue
@DavidePastore DavidePastore modified the milestones: 3.1.0, future-release Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants