Если <a href="https://gist.github.com/nizom333/0e84e90627e01401f7d7a790b58b6c9d" rel="nofollow">это</a> ( <i>ссылку взял из комментов в документации</i> ) и есть класс <code>\Bitrix\Main\XmlWriter</code> , то с его помощью - никак. <br/> <br/> Он пишет сразу в файл, так что и регуляркой итоговый результат не пройти. <br/> <br/> Можно залезть в него рефлексией, но в программировании это моветон и читабельность кода будет ухудшена. <br/> <br/> Самый оптимальный вариант - наследовать этот класс, изменить несколько его функций и использовать унаследованный класс. Примерно так: <br/> <pre><code class="php">class AppXmlWriter extends XmlWriter
{
private $file = '';
private $charset = '';
private $tab = 0;
private $f = null;
private $lowercaseTag = false;
private $errors = array();
// конструктор скопирован, т.к. там все private
public function __construct(array $params)
{
if (isset($params['file']))
{
$server = \Bitrix\Main\Application::getInstance()->getContext()->getServer();
$this->file = $server->getDocumentRoot() . trim($params['file']);
// create new file
if (
isset($params['create_file']) &&
$params['create_file'] === true &&
is_writable($this->file)
)
{
unlink($this->file);
}
}
if (isset($params['charset']))
{
$this->charset = trim($params['charset']);
}
else
{
$this->charset = SITE_CHARSET;
}
if (isset($params['lowercase']) && $params['lowercase'] === true)
{
$this->lowercaseTag = true;
}
if (isset($params['tab']))
{
$this->tab = (int)$params['tab'];
}
}
public function prepareAttributes(array $attributes): string
{
if (empty($attributes)) {
return '';
}
$result = '';
foreach ($attributes as $key => $value) {
$result .= sprintf(' %s="%s"', $key, $value);
}
return $result;
}
public function writeBeginTag($code, array $attributes = [])
{
if (!$this->f) {
return;
}
fwrite($this->f, str_repeat("\t", $this->tab) . '<' . $this->prepareTag($code) . $this->prepareAttributes($attributes) . '>' . PHP_EOL);
$this->tab++;
}
public function writeFullTag($code, $value, array $attributes = [])
{
if (!$this->f) {
return;
}
$code = $this->prepareTag($code);
$codeAttributes = $this->prepareAttributes($attributes);
fwrite($this->f,
str_repeat("\t", $this->tab) .
(
trim($value) == ''
? '<' . $code . $codeAttributes . ' />' . PHP_EOL
: '<' . $code . $codeAttributes . '>' .
$this->prepareValue($value) .
'</' . $code . '>' . PHP_EOL
)
);
}
}</code></pre>