Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.
Help keep Vanilla free:// An empty shell for housing an xml response.
class XMLResponse {}
function ParseXmlFile($FileLocation) {
$Lines = file($FileLocation);
$XML = new XMLResponse();
// Loop through each of the lines of the response and get the
// properties/values
for ($i = 0; $i < count($Lines); $i++) {
$Matches = false;
preg_match("/(<([^<>\s]*)(\s[^<>]*)?>)(.+?)(<([^<>\s]*)(\s[^<>]*)?>)/",
$Lines[$i],
$Matches);
if (count($Matches) == 7) {
$Property = $Matches[2];
$Value = $Matches[4];
$XML->$Property = $Value;
}
}
return $XML;
}
}
/* Assuming the xml file contains something like this:
<root>
<status>ok</status>
<id>123456</id>
<username>marky</username>
</root>
*/
$MyXml = ParseXmlFile("/path/to/my/xml/file.xml");
echo($MyXml->username." has an id of ".$MyXml->id." and has a status of ".$MyXml->status);
/*
Will Print:
marky has an id of 123456 and has a status of ok
*/
<?xml version="1.0" encoding="UTF-8"?>
<gallery>
<album id="flowers" title="" description="Photos of flowers"> />
</album>
<album id="cars" title="" description="Photos of cars"> />
</album>
<album id="animals" title="" description="Photos of erm, animals"> />
</album>
</gallery>
1 to 8 of 8