En iyi yolu nedir?
XML SimpleXML . It turns an XML document into an object that provides structured access kullanın.
, Bir string depolanan bir XML belgesinden bir SimpleXMLElement nesnesi oluşturmak için dize geçmek için simplexml_load_string (). Bu SimpleXML nesnesi döndürür.
Örnek olarak, bu göz önünde bulundurun:
$channel =<<<_XML_
<channel>
<title>Example title</title>
<link>http://example.com/</link>
<description>Example desccription</description>
</channel>
_XML_;
// The XML that needs to be parsed
$xml = simplexml_load_string($channel); // create a SimpleXML object.
print "The $xml->title channel is available at $xml->link. ";
basacaktır:
The Example title is available at http://example.com/.
You can use the following program also for creating the SimpleXml object. Using SimpleXml object you can access the xml tags.
test.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<employee>
<name> Shyam </name>
<age> 20 </age>
<place> Chennai </place>
</employee>
file.php
<?php
$xml = simplexml_load_file("test.xml");
echo $xml->getName() . "<br />";
foreach($xml->children() as $child)
{
echo $child->getName() . ": " . $child . "<br />";
}
?>
"XML olsun" tarafından, bir uzak bir kaynaktan almak, ya da zaten bir XML metnini ayrıştırmak demek?
Eski için (URL'leri uygulanan file_get_contents veya benzeri fonksiyonlar üzerinden) URL içerik yüklemek için PHP'nin yerleşik yeteneğini kullanmak, ya da (çoğu PHP dağıtımları ile standart olarak yer almaktadır) cURL gibi bir kitaplığı kullanın ya.
İkincisi, kütüphaneler gibi SimpleXML (ayrıca standart dahil) oldukça yararlı olabilir.