Skip to content

Class XmlDocumentWriter

HorstOeko edited this page Dec 21, 2024 · 2 revisions

Summary

Class representing the XML writer helper

Methods

__construct

Summary

Constructor

Signature

public function __construct(string $tag, string $version = '1.0', string $encoding = 'UTF-8'): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
tag string
Specify the root tag of the document
version string
encoding string

Returns

Returns a value of type \XmlDocumentWriter

addNamespace

Summary

Add a namespace declaration to the root

Signature

public function addNamespace(string $namespace, string $value): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
namespace string
value string

Returns

Returns a value of type \XmlDocumentWriter

startElement

Summary

Start an element

Signature

public function startElement(string $tag, string $value = ''): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
tag string
value string

Returns

Returns a value of type \XmlDocumentWriter

endElement

Summary

End an element

Signature

public function endElement(): \XmlDocumentWriter
{
}

Returns

Returns a value of type \XmlDocumentWriter

element

Summary

Write a single element

Signature

public function element(string $tag, ?string $value = ''): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
tag string
value string ✔️

Returns

Returns a value of type \XmlDocumentWriter

elementIf

Summary

Write a single element if $condition is true

Signature

public function elementIf(bool $condition, string $tag, ?string $value = ''): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
condition bool
tag string
value string ✔️

Returns

Returns a value of type \XmlDocumentWriter

elementWithAttribute

Summary

Write a single element with a single attribute

Signature

public function elementWithAttribute(
  string $tag,
  ?string $value = '',
  ?string $attributeName = '',
  ?string $attributeValue = '',
): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
tag string
value string ✔️
attributeName string ✔️
attributeValue string ✔️

Returns

Returns a value of type \XmlDocumentWriter

elementWithMultipleAttributes

Summary

Write a single element with multiple attributes

Signature

public function elementWithMultipleAttributes(
  string $tag,
  ?string $value = '',
  array $attributes = [],
): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
tag string
value string ✔️
attributes array

Returns

Returns a value of type \XmlDocumentWriter

attribute

Summary

Add an attribute to latest element when value is given

Signature

public function attribute(string $name, ?string $value = null): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
name string
value string ✔️

Returns

Returns a value of type \XmlDocumentWriter

changeRoot

Summary

Change the root of the document

Signature

public function changeRoot(string $newRoot): \XmlDocumentWriter
{
}

Parameters

Name Type Allows Null Description
newRoot string

Returns

Returns a value of type \XmlDocumentWriter

group

Summary

Start a group

Signature

public function group(string $tagName, mixed $callback): void
{
}

Parameters

Name Type Allows Null Description
tagName string
callback mixed

saveXmlString

Summary

Get XML as a string

Signature

public function saveXmlString(): string
{
}

Returns

Returns a value of type string

saveXmlFile

Summary

Save XML to file

Signature

public function saveXmlFile(string $filename): int|false
{
}

Parameters

Name Type Allows Null Description
filename string

Returns

Returns a value of type int|false