public function FormatConverter::xml_to_standard in Lingotek Translation 8
Converts source XML into a StandardImportObject that can be imported into WP @author Unkown
Parameters
object $source_doc source document:
string $xml_string XML string that is then parsed to get the relevant: information for the title and body
Return value
StandardImportObject That can be imported into WP
File
- src/
Form/ FormatConverter.php, line 164
Class
Namespace
Drupal\lingotek\FormCode
public function xml_to_standard($doc, $xml_string) {
$content = t('We could not parse the data from this document.
Are you sure that it is in a recognizable format, such as JSON, XML, HTML, or plain text?');
$title = t('No title found');
$xml = new \SimpleXMLElement($xml_string);
if ($xml === false) {
echo t("Failed to load XML");
}
$found_content = (array) $xml
->xpath('//element');
if ($found_content) {
$content = (string) $found_content[0];
$title = (string) $found_content[1];
}
else {
$error = true;
}
return new StandardImportObject($title, $content, $error);
}