public function MigrateXMLReader::__construct in Migrate 6.2
Same name and namespace in other branches
- 7.2 plugins/sources/xml.inc \MigrateXMLReader::__construct()
Prepares our extensions to the XMLReader object.
Parameters
$xml_url: URL of the XML file to be parsed.
$element_query: Query string in a restricted xpath format, for selecting elements to be returned by the interator. Supported syntax:
- The full path to the element must be specified; i.e., /file/article rather than //article.
- The elements may be filtered by attribute value by appending [@attribute="value"].
$id_query: Query string to the unique identifier for an element, relative to the root of that element. This supports the full xpath syntax.
File
- plugins/
sources/ xml.inc, line 682 - Support for migration from XML sources.
Class
- MigrateXMLReader
- Makes an XMLReader object iterable, returning elements matching a restricted xpath-like syntax.
Code
public function __construct($xml_url, $element_query, $id_query) {
$this->reader = new XMLReader();
$this->url = $xml_url;
$this->elementQuery = $element_query;
$this->idQuery = $id_query;
// Suppress errors during parsing, so we can pick them up after
libxml_use_internal_errors(TRUE);
// Parse the element query. First capture group is the element path, second
// (if present) is the attribute.
preg_match_all('|^/([^\\[]+)(.*)$|', $element_query, $matches);
$element_path = $matches[1][0];
$this->elementsToMatch = explode('/', $element_path);
$attribute_query = $matches[2][0];
if ($attribute_query) {
// Matches [@attribute="value"] (with either single- or double-quotes).
preg_match_all('|^\\[@([^=]+)=[\'"](.*)[\'"]\\]$|', $attribute_query, $matches);
$this->attributeName = $matches[1][0];
$this->attributeValue = $matches[2][0];
}
}