Build XML in PHP easily and concisely.
$xml = new XMLElement(
qualifiedName: "elementName",
value: "element value",
);
print($xml->buildXML());
<elementName>element value</elementName>
$xml = new XMLElement(
qualifiedName: "elementName",
value: "element value",
attributes: [
"attribute1" => "attribute 1 value",
"attribute2" => "attribute 2 value",
],
);
print($xml->buildXML());
<elementName attribute1="attribute 1 value" attribute2="attribute 2 value">element value</elementName>
$xml = new XMLElement(
"elementName",
"element value",
[
"attribute1" => "attribute 1 value",
"attribute2" => "attribute 2 value",
],
[
new XMLElement(
"child1",
children: [
new XMLElement(
"childOfChild",
"valueOfChild",
)
]
),
new XMLElement(
"AnotherChild",
"child2 Value",
),
],
);
print($xml->buildXML());
<elementName attribute1="attribute 1 value" attribute2="attribute 2 value">element value<child1><childOfChild>valueOfChild</childOfChild></child1><AnotherChild>child2 Value</AnotherChild></elementName>