# tablepress/3.4/libraries/vendor/PhpSpreadsheet/Shared/XMLWriter.php

TablePress – Tables in WordPress made easy, version 3.4. 110 lines.

- Page: https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Shared/XMLWriter.php
- Raw: https://pluginprobe.com/plugins/tablepress/3.4/raw/libraries/vendor/PhpSpreadsheet/Shared/XMLWriter.php
- Modified: 2026-09-30T03:50:46+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/tablepress/3.4/code/libraries/vendor/PhpSpreadsheet/Shared/XMLWriter.php#L10-L20`.

```php
<?php

namespace TablePress\PhpOffice\PhpSpreadsheet\Shared;

use TablePress\PhpOffice\PhpSpreadsheet\Exception as SpreadsheetException;

class XMLWriter extends \XMLWriter
{
	public static bool $debugEnabled = false;

	/** Temporary storage method */
	const STORAGE_MEMORY = 1;
	const STORAGE_DISK = 2;

	/**
	 * Temporary filename.
	 */
	private string $tempFileName = '';

	/**
	 * Create a new XMLWriter instance.
	 *
	 * @param int $temporaryStorage Temporary storage location
	 * @param ?string $temporaryStorageFolder Temporary storage folder
	 */
	public function __construct(int $temporaryStorage = self::STORAGE_MEMORY, ?string $temporaryStorageFolder = null)
	{
		// Open temporary storage
		if ($temporaryStorage == self::STORAGE_MEMORY) {
			$this->openMemory();
		} else {
			// Create temporary filename
			if ($temporaryStorageFolder === null) {
				$temporaryStorageFolder = File::sysGetTempDir();
			}
			$this->tempFileName = (string) @tempnam($temporaryStorageFolder, 'xml');

			// Open storage
			if (empty($this->tempFileName) || $this->openUri($this->tempFileName) === false) {
				// Fallback to memory...
				$this->openMemory();
				if ($this->tempFileName != '') {
					@unlink($this->tempFileName);
				}
				$this->tempFileName = '';
			}
		}

		// Set default values
		if (self::$debugEnabled) {
			$this->setIndent(true);
		}
	}

	/**
	 * Destructor.
	 */
	public function __destruct()
	{
		// Unlink temporary files
		// There is nothing reasonable to do if unlink fails.
		if ($this->tempFileName != '') {
			@unlink($this->tempFileName);
		}
	}

	/**
	 * Unserialization is not allowed. This needs to be enforced
	 * in the class before Php8.6, but, with that release,
	 * this method is no longer needed and will not be executed.
	 *
	 * @see https://github.com/php/php-src/pull/21694
	 *
	 * @param mixed[] $data
	 */
	public function __unserialize(array $data): void
	{
		$this->tempFileName = '';

		throw new SpreadsheetException('Unserialize not permitted');
	}

	/**
	 * Get written data.
	 */
	public function getData(): string
	{
		if ($this->tempFileName == '') {
			return $this->outputMemory(true);
		}
		$this->flush();

		return file_get_contents($this->tempFileName) ?: '';
	}

	/**
	 * Wrapper method for writeRaw.
	 *
	 * @param null|string|string[] $rawTextData
	 */
	public function writeRawData($rawTextData): bool
	{
		if (is_array($rawTextData)) {
			$rawTextData = implode("\n", $rawTextData);
		}

		return $this->text($rawTextData ?? '');
	}
}

```
