class FeedsExQueryPathXml in Feeds extensible parsers 7
Same name and namespace in other branches
- 7.2 src/FeedsExQueryPathXml.inc \FeedsExQueryPathXml
Parses XML documents with QueryPath.
Hierarchy
- class \FeedsExBase extends \FeedsParser
- class \FeedsExXml
- class \FeedsExQueryPathXml
- class \FeedsExXml
Expanded class hierarchy of FeedsExQueryPathXml
2 string references to 'FeedsExQueryPathXml'
- FeedsExQueryPathXml.test in src/
Tests/ FeedsExQueryPathXml.test - feeds_ex_feeds_plugins in ./
feeds_ex.feeds.inc - Implements hook_feeds_plugins().
File
- src/
FeedsExQueryPathXml.inc, line 11 - Contains FeedsExXml.
View source
class FeedsExQueryPathXml extends FeedsExXml {
/**
* Options passed to QueryPath.
*
* @var array
*/
protected $queryPathOptions = array(
'ignore_parser_warnings' => TRUE,
'use_parser' => 'xml',
'strip_low_ascii' => FALSE,
'replace_entities' => FALSE,
'omit_xml_declaration' => TRUE,
'encoding' => 'UTF-8',
);
/**
* {@inheritdoc}
*/
protected function executeContext(FeedsSource $source, FeedsFetcherResult $fetcher_result) {
$document = $this
->prepareDocument($source, $fetcher_result);
$parser = new QueryPath($document, NULL, $this->queryPathOptions);
$query_path = $parser
->find($this->config['context']['value']);
$state = $source
->state(FEEDS_PARSE);
if (!$state->total) {
$state->total = $query_path
->size();
}
$start = (int) $state->pointer;
$state->pointer = $start + $source->importer
->getLimit();
$state
->progress($state->total, $state->pointer);
return $query_path
->slice($start, $source->importer
->getLimit());
}
/**
* {@inheritdoc}
*/
protected function executeSourceExpression($machine_name, $expression, $row) {
$result = new QueryPath($row, $expression, $this->queryPathOptions);
if ($result
->size() == 0) {
return;
}
$config = $this->config['sources'][$machine_name];
$return = array();
if (strlen($config['attribute'])) {
foreach ($result as $node) {
$return[] = $node
->attr($config['attribute']);
}
}
elseif (!empty($config['inner'])) {
foreach ($result as $node) {
$return[] = $node
->innerXML();
}
}
elseif (!empty($config['raw'])) {
foreach ($result as $node) {
$return[] = $this
->getRawValue($node);
}
}
else {
foreach ($result as $node) {
$return[] = $node
->text();
}
}
// Return a single value if there's only one value.
return count($return) === 1 ? reset($return) : $return;
}
/**
* Returns the raw value.
*
* @param QueryPath $node
* The QueryPath object to return a raw value for.
*
* @return string
* A raw string value.
*/
protected function getRawValue(QueryPath $node) {
return $node
->xml();
}
/**
* {@inheritdoc}
*/
protected function validateExpression(&$expression) {
$expression = trim($expression);
if (!$expression) {
return;
}
try {
$parser = new QueryPath(NULL, $expression);
} catch (CSSParseException $e) {
return check_plain($e
->getMessage());
}
}
/**
* {@inheritdoc}
*/
protected function configFormTableHeader() {
return array(
'attribute' => t('Attribute'),
) + parent::configFormTableHeader();
}
/**
* {@inheritdoc}
*/
protected function configFormTableColumn(array &$form_state, array $values, $column, $machine_name) {
switch ($column) {
case 'attribute':
return array(
'#type' => 'textfield',
'#title' => t('Attribute name'),
'#title_display' => 'invisible',
'#default_value' => !empty($values['attribute']) ? $values['attribute'] : '',
'#size' => 10,
'#maxlength' => 1024,
);
default:
return parent::configFormTableColumn($form_state, $values, $column, $machine_name);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsExBase:: |
protected | property | The encoder used to convert encodings. | |
FeedsExBase:: |
protected | property | The object used to display messages to the user. | |
FeedsExBase:: |
protected | function | Renders our debug messages into a list. | |
FeedsExBase:: |
protected | function | Executes the source expressions. | |
FeedsExBase:: |
public | function | Returns the encoder. | |
FeedsExBase:: |
protected | function | Returns the configuration form table header. | |
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
public | function | Returns the messenger. | |
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
protected | function | Returns whether or not this parser uses a context query. | 2 |
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
protected | function | Loads the necessary library. | 2 |
FeedsExBase:: |
protected | function | Logs errors. | |
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
protected | function | Performs the actual parsing. | 2 |
FeedsExBase:: |
protected | function | Prepares the expressions for parsing. | |
FeedsExBase:: |
protected | function | Prepares the raw string for parsing. | |
FeedsExBase:: |
protected | function | Prepares the variable map used to substitution. | |
FeedsExBase:: |
protected | function | Prints errors to the screen. | |
FeedsExBase:: |
public | function | Sets the encoder. | |
FeedsExBase:: |
public | function | Sets the messenger to be used to display messages. | |
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
public | function | ||
FeedsExQueryPathXml:: |
protected | property | Options passed to QueryPath. | |
FeedsExQueryPathXml:: |
protected | function |
Returns a form element for a specific column. Overrides FeedsExXml:: |
|
FeedsExQueryPathXml:: |
protected | function |
Reuturns the list of table headers. Overrides FeedsExXml:: |
|
FeedsExQueryPathXml:: |
protected | function |
Returns rows to be parsed. Overrides FeedsExXml:: |
|
FeedsExQueryPathXml:: |
protected | function |
Executes a single source expression. Overrides FeedsExXml:: |
|
FeedsExQueryPathXml:: |
protected | function | Returns the raw value. | 1 |
FeedsExQueryPathXml:: |
protected | function |
Validates an expression. Overrides FeedsExXml:: |
|
FeedsExXml:: |
protected | property |
The class used as the text encoder. Overrides FeedsExBase:: |
2 |
FeedsExXml:: |
protected | property | The previous value for the entity loader. | |
FeedsExXml:: |
protected | property | The previous value for XML error handling. | |
FeedsExXml:: |
protected | property | The FeedsExXpathDomXpath object used for parsing. | |
FeedsExXml:: |
protected | function |
Allows subclasses to cleanup after parsing. Overrides FeedsExBase:: |
|
FeedsExXml:: |
public | function |
Overrides FeedsExBase:: |
|
FeedsExXml:: |
public | function |
Overrides FeedsExBase:: |
|
FeedsExXml:: |
public | function |
Overrides FeedsExBase:: |
|
FeedsExXml:: |
protected | function |
Returns the errors after parsing. Overrides FeedsExBase:: |
|
FeedsExXml:: |
protected | function | Returns the inner XML of a DOM node. | |
FeedsExXml:: |
protected | function | Returns the raw XML of a DOM node. | 1 |
FeedsExXml:: |
protected | function | Returns the options for phptidy. | 2 |
FeedsExXml:: |
protected | function | Prepares the DOM document. | 2 |
FeedsExXml:: |
protected | function |
Allows subclasses to prepare for parsing. Overrides FeedsExBase:: |
1 |
FeedsExXml:: |
protected | function |
Starts internal error handling. Overrides FeedsExBase:: |
|
FeedsExXml:: |
protected | function |
Stops internal error handling. Overrides FeedsExBase:: |