maxnz / xml-builder
Build XML easily and concisely
v1.0.1
2022-05-05 18:48 UTC
README
Build XML in PHP easily and concisely.
Usage
A Single XML element
$xml = new XMLElement( qualifiedName: "elementName", value: "element value", ); print($xml->buildXML());
<elementName>element value</elementName>
Adding Attributes
$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>
Child Elements
$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>