SimpleXML or XMLReader?

which one of the two is more common? I want to read the version number http://freshmeat.net/projects-xml/mysql/mysql.xml?branch_id=46519 , but I want to use the one that more people have.

If you know another way to get the latest stable version number from mysql, tell me;)

+3
source share
4 answers

For this task, reading the document in DomDocumentand using DomXPathis probably more suitable.

To answer your question, both libraries (as well as DomDocument+ DomXPath) are standard outfits with PHP5, so they will be equally good.

+5
source

SimpleXML. , XML, Dom, , Dom, xpath, Dom:

$xml = simplexml_load_file(
    'http://freshmeat.net/projects-xml/mysql/mysql.xml?branch_id=46519'
    );
$result = $xml->xpath('//latest_release/latest_release_version'); 
// or '//latest_release/*' if you'd rather loop through all release information.

while(list( , $node) = each($result))
    echo $node, "\n";
+3

XMLreader, simpleXML .

+1

SimpleXML was introduced in PHP5, while XmlReader was enabled by default in version 5.1, so the first is probably the best way:

$struct = simplexml_load_string($xml);
$version = (string)$struct->project->latest_release->latest_release_version;

However, if you do not perform any other XML processing and do not want to maximize compatibility, you can simply rename the XML:

if(preg_match('/<latest_release_version>(.*?)<\\/latest_release_version>/', $xml, $matches)){
$version = $matches[1];
}

This is messy than the XML processing is correct, but probably faster and supported by almost all PHP installations.

0
source

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


All Articles