Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return DOMDocument instead of DOMElement from XMLParserExtractor #1222

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ public function extract(FlowContext $context) : \Generator
foreach ($this->elements as $element) {
if ($shouldPutInputIntoRows) {
$rowData = [
'node' => $this->createDOMElement($element),
'node' => $this->createDOMNode($element),
'_input_file_uri' => $stream->path()->uri(),
];
} else {
$rowData = ['node' => $this->createDOMElement($element)];
$rowData = ['node' => $this->createDOMNode($element)];
}

$signal = yield array_to_rows($rowData, $context->entryFactory(), $stream->path()->partitions());
Expand All @@ -126,11 +126,11 @@ public function extract(FlowContext $context) : \Generator
foreach ($this->elements as $element) {
if ($shouldPutInputIntoRows) {
$rowData = [
'node' => $this->createDOMElement($element),
'node' => $this->createDOMNode($element),
'_input_file_uri' => $stream->path()->uri(),
];
} else {
$rowData = ['node' => $this->createDOMElement($element)];
$rowData = ['node' => $this->createDOMNode($element)];
}

$signal = yield array_to_rows([$rowData], $context->entryFactory(), $stream->path()->partitions());
Expand Down Expand Up @@ -194,18 +194,12 @@ public function withXMLNodePath(string $xmlNodePath) : self
return $this;
}

private function createDOMElement(string $xmlString) : \DOMElement
private function createDOMNode(string $xmlString) : \DOMNode
{
$doc = new \DOMDocument();
$doc->loadXML($xmlString);

$element = $doc->documentElement;

if ($element === null) {
throw new RuntimeException('Cannot create DOMElement from XML string: ' . $xmlString);
}

return $element;
return $doc;
}

private function freeParser() : void
Expand Down