What XML parser do you use for PHP?

I like the XMLReader class for its simplicity and speed. But I like the functions associated with xml_parse, as it better allows you to recover errors. It would be nice if the XMLReader class throws exceptions for things like invalid ref entities, and not just issues a warning.

+3
source share
5 answers

I would avoid SimpleXML if possible. Although this looks very tempting when you avoid a lot of ugly code, this is just what the name suggests: simple. For example, he cannot handle this:

<p>
    Here is <strong>a very simple</strong> XML document.
</p>

DOM. . DOM- Javascript, .

+4
+3

SimpleXML DOM , XML-, SimpleXML DOM.

:

$simplexml = simplexml_load_string("<xml></xml>");
$simplexml->simple = "it is simple.";

$domxml = dom_import_simplexml($simplexml);
$node = $domxml->ownerDocument->createElement("dom", "yes, with DOM too.");
$domxml->ownerDocument->firstChild->appendChild($node);

echo (string)$simplexml->dom;

:

"yes, with DOM too."

, ( simplexml, dom), PHP .

, SimpleXML, / .

. http://code.google.com/p/blibrary/source/browse/trunk/classes/bXml.class.inc .

XML (-2MB), DOM/SimpleXML ( x2 x3). XML (+ 2 ) XMLReader/XMLWriter SAX- . 14 + XMLReader/XMLWriter.

+2

PHP5 XML . XML .

Theres " XML PHP IBM developerWorks.

"DOM analysis, fully compliant with the W3C standard, is a familiar option and your choice for complex but relatively small documents. SimpleXML is the way for simple and not too large XML documents, and XMLReader, simpler and faster than SAX, is parser flow for large documents. "

+1
source

I mostly stick to SimpleXML, at least when PHP5 is available to me.

http://www.php.net/simplexml

0
source

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


All Articles