Feature: element_encode()
lykciv opened this issue · 1 comments
lykciv commented
Feature Request
Q | A |
---|---|
New Feature | yes |
RFC | no |
BC Break | no |
Summary
I have come across a scenario where I needed to generated a part of an xml document instead of the full document. The available helper functions only allow for generating full documents. It might be useful to have a helper function like element_encode()
.
Example full doc
$doc = [
'Data' => [
'Hello' => 'World',
'Extra' => [
'Lorem' => 'Ipsum',
],
],
];
xml_encode($doc);
Output
<?xml version="1.0"?>
<Data>
<Hello>World</Hello>
<Extra>
<Lorem>Ipsum</Lorem>
</Extra>
</Data>
Example partial doc
$element = [
'Lorem' => 'Ipsum',
];
element_encode($element);
Output
<Lorem>Ipsum</Lorem>
veewee commented
It is possible by using document_encode($data)
and format the document_element()
through to_xml()
.
$document = document_encode($data, ...$configurators);
$result = xml_string()($document->locate(document_element()));
But this sure sounds like a lovely shortcut function to have in the toolbelt.
Feel free to provide a PR.