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

Cdata functions #53

Merged
merged 2 commits into from
Jul 20, 2023
Merged

Cdata functions #53

merged 2 commits into from
Jul 20, 2023

Conversation

veewee
Copy link
Owner

@veewee veewee commented Jul 20, 2023

Q A
Type feature
BC Break no
Fixed issues

Summary

assert_cdata

Assert if a node is of type DOMCdataSection.

use Psl\Type\Exception\AssertException;
use function VeeWee\Xml\Dom\Assert\assert_cdata;

try {
    assert_cdata($someNode)
} catch (AssertException $e) {
    // Deal with it
}

cdata builder

Operates on a DOMNode and creates a DOMCdataSection.
It can contain a set of configurators that can be used to dynamically change the cdata's contents.

use function VeeWee\Xml\Dom\Builder\attribute;
use function VeeWee\Xml\Dom\Builder\element;
use function VeeWee\Xml\Dom\Builder\cdata;
use function VeeWee\Xml\Dom\Builder\children;

element('hello', children(
    cdata('<html>world</html>')
));
<hello><![CDATA[<html>world</html>]]></hello>

is_cdata

Checks if a node is of type DOMCdataSection.

use function VeeWee\Xml\Dom\Predicate\is_cdata;

if (is_cdata($someNode)) {
   // ...
}

encoding will now accept @cdata

xml_encode(
            [
                '@attributes' => [
                    'id' => 2,
                    'test:type' => 'hello'  
                ],
                '@cdata' => '<html>Moon</html>'
            ]
);

(decoding will not result in @cdata but in @value with escaped XML entitites - because node children could be a mix of both text and cdata)

@veewee veewee added the enhancement New feature or request label Jul 20, 2023
@veewee veewee added this to the 2.7.0 milestone Jul 20, 2023
@veewee veewee changed the title Cdata Cdata functions Jul 20, 2023
@veewee veewee merged commit ad6651f into main Jul 20, 2023
20 checks passed
@veewee veewee deleted the cdata branch July 20, 2023 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant