class FeedsExQueryPathXml in Feeds extensible parsers 7.2
Same name and namespace in other branches
- 7 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
7 string references to 'FeedsExQueryPathXml'
- FeedsExQueryPathXmlUnitTests::testAttributeParsing in src/
Tests/ FeedsExQueryPathXml.test - Tests grabbing an attribute.
- FeedsExQueryPathXmlUnitTests::testBatchParsing in src/
Tests/ FeedsExQueryPathXml.test - Tests that batch parsing works.
- FeedsExQueryPathXmlUnitTests::testCP866Encoded in src/
Tests/ FeedsExQueryPathXml.test - Tests parsing a CP866 (Russian) encoded file.
- FeedsExQueryPathXmlUnitTests::testEUCJPEncodedNoDeclaration in src/
Tests/ FeedsExQueryPathXml.test - Tests a EUC-JP (Japanese) encoded file without the encoding declaration.
- FeedsExQueryPathXmlUnitTests::testSimpleParsing in src/
Tests/ FeedsExQueryPathXml.test - Tests simple parsing.
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();
}
$state->start = $state->pointer ? $state->pointer : 0;
$limit = $state->start + $source->importer
->getLimit();
$state->pointer = $limit > $state->total ? $state->total : $limit;
$state
->progress($state->total, $state->pointer);
return $query_path
->slice($state->start, $source->importer
->getLimit());
}
/**
* {@inheritdoc}
*/
protected function executeSourceExpression($machine_name, $expression, $row) {
$result = new QueryPath($row, $expression, $this->queryPathOptions);
if ($result
->size() == 0) {
return;
}
if (strlen($this->config['sources'][$machine_name]['attribute'])) {
return $result
->attr($this->config['sources'][$machine_name]['attribute']);
}
$return = array();
if (!empty($this->config['sources'][$machine_name]['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, $column_name, array $source) {
switch ($column_name) {
case 'attribute':
return array(
'#type' => 'textfield',
'#title' => t('Attribute name'),
'#title_display' => 'invisible',
'#default_value' => !empty($source['attribute']) ? $source['attribute'] : '',
'#size' => 10,
);
default:
return parent::configFormTableColumn($form_state, $column_name, $source);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsExBase:: |
protected | property | Whether the current system handles mb_* functions. | |
FeedsExBase:: |
protected | property | The object used to display messages to the user. | |
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
protected | function | Renders our debug messages into a list. | |
FeedsExBase:: |
protected | function | Delegates parsing to the subclass. | |
FeedsExBase:: |
protected | function | Detects the encoding of a string. | |
FeedsExBase:: |
protected | function | Executes the source expressions. | |
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 | Prepares the expressions 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 messenger to be used to display messages. | |
FeedsExBase:: |
public | function | Sets the multibyte handling. | |
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
public | function | ||
FeedsExBase:: |
protected | function | 1 | |
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 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:: |
protected | function |
Converts a string to UTF-8. Overrides FeedsExBase:: |
2 |
FeedsExXml:: |
protected | function |
Returns the errors after parsing. Overrides FeedsExBase:: |
|
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:: |