.pdf)
WHM Plugins
simplexml_load_string() and assign its return output to a value.
This will transform the provided XML into a SimpleXML object. SimpleXML objects are similar to associative arrays. The code in the example above should produce output similar to:$xml_string = "<xml><CPDATA><user>someusername</user></CPDATA></xml>"; $xml_object = simplexml_load_string($xml_string); var_dump($xml_object);
object(SimpleXMLElement)#1 (1) {
["CPDATA"]=>
object(SimpleXMLElement)#2 (1) {
["user"]=>
string(12) "someusername"
}
}
Any data contained within this object can be accessed by treating each container as an associative. This means that if you would like to print data contained within the <user> tag, you would need to call the following element of the object:
$xml_object->CPDATA->user;
XML::Simple Perl module using the following command:
Once the module has been loaded, several functions will also be loaded automatically. One of these functions is calledUse XML::Simple
XMLin. Using this function, you can translate XML data into Perl hash references.
This will return the following output:use XML::Simple; use Data::Dumper; my $xml_string = "<xml><CPDATA><user>someusername</user></CPDATA></xml>"; my $xml_hashref = XMLin($xml_string); print Dumper $xml_hashref
$VAR1 = {
'CPDATA' => {
'user' => 'someusername'
}
};
In order to access this data, you will need to call each key in the hash reference as it corresponds to the container in the XML data, like so:
$xml_hashref->{'CPDATA'}->{'user'};
Copyright © cPanel 2000–2011.