Is it better to use pure DOM methods or string concatenation to create a very dynamic xml file?

I basically have to query the database in order to capture all the active properties, and then grab the content under each property for sections such as placement / experience and based on this generate basically a sitemap.

I am wondering if I should use only DOM methods (can I make a hundred or so createElements, inside loops, appendChildetc.) or just do a giant string concatenation and confirm that then render it as xml?

+3
source share
4 answers

DOM XML. , .

$xmlBlock = '<foo>';
$xmlBlock .= '<bar>'.htmlspecialchars('baz', ENT_NOQUOTES, 'utf-8', false).'</bar>';
$xmlBlock .= '</foo>';

:

$node = $dom->createElement('foo');
$node->appendChild($dom->createElement('bar', 'baz'));

, ...

+4

, .

$myXml  = "<?xml ...... ";
$myXml .= "<rootNode>";
$myXml .= "<child>";

..

+2

, , , . XML DOM- .

+1

, XML. , , , XML .., . , , DTD.

I don't know anything about PHP, but Android XmlSerializer is a good minimum API model that you need to provide guaranteed -built XML without creating a DOM in memory as part of the process. The code used is not complicated and can be built and tested separately from any applications that use it.

0
source

Source: https://habr.com/ru/post/1759381/


All Articles