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

How to render some element as CDATA? #222

Open
komareklukas opened this issue Aug 22, 2022 · 3 comments
Open

How to render some element as CDATA? #222

komareklukas opened this issue Aug 22, 2022 · 3 comments

Comments

@komareklukas
Copy link

komareklukas commented Aug 22, 2022

I have feed:

<?xml version="1.0" encoding="UTF-8"?>
<SHOP>
	<SHOPITEM id="392">
		<NAME>Andělika obrovská</NAME>
		<GUID>575c1bb4-710a-11eb-b3db-0cc47a6c9370</GUID>
		<SHORT_DESCRIPTION><![CDATA[<p>Výška sazenice cca 20 cm</p>]]></SHORT_DESCRIPTION>
	</SHOPITEM>
</SHOP>

I need to parse it and then render it.

I would like to ask your advice on how to render "SHORT_DESCRIPTION" as CDATA.

$reader = $service->getReader();
$reader->xml(file_get_contents($feedUrl));
$xml = $reader->parse();

//bdump($xml);

$writer = $service->getWriter();
$writer->openMemory();
$writer->setIndent(true);
$writer->startDocument('1.0', 'UTF-8');
$writer->namespaceMap[''] = '';
$writer->write($xml);

//bdump($writer->outputMemory());

Can you please add the code to my sample?

@evert
Copy link
Member

evert commented Aug 22, 2022

Why do you need it? It's almost always a mistake.

@komareklukas
Copy link
Author

Because the "SHORT_DESCRIPTION" element contains HTML code that consists of "<" and ">" characters.

Element must be rendered as "CDATA". It is a mandatory requirement for importing feed in the e-shop platform shoptet.cz.

@evert
Copy link
Member

evert commented Aug 22, 2022

It's much better to map those to &lt; ad &gt;. If your e-shop platform requires it, they use a broken xml parser which would be very surprising!

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

No branches or pull requests

2 participants