Skip to content

Conversation

@d3f3kt
Copy link

@d3f3kt d3f3kt commented Feb 29, 2020

This new xml writer provides 3 more functions which are essential to handle complex xml structures.

  1. It's now possible to provide attributes to the root element. Because this attributes are given as an additional constructor argument, i have created a new class to avoid bc breaks.

As an alternative, a factory could be used which would call a setter Method.

  1. Nested array can be handled now.
  2. XML attributes can be defined with a traling '@'.

Example:

$writer = new \Port\Xml\AdvancedXmlWriter(
    new \XMLWriter(), '/tmp/aaa.xml', 'rootElement',
    ['rootAttribute' => 'rootValue']
);

$xml = [
    'key1' => 'value1',
    '@attribute1' => 'attributeValue1',
    'collection' => [
        'foo' => 'bar',
    ],
];
<?xml version="1.0"?>
<rootElement rootAttribute="rootValue">
    <item attribute1="attributeValue1">
        <key1>value1</key1>
        <collection>
            <foo>bar</foo>
        </collection>
    </item>
</rootElement>

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.

1 participant