alcamo / xml-creation
Simple classes to create XML code without need for a factory
Installs: 148
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/alcamo/xml-creation
Requires
- php: 7.3 - 8.0
- alcamo/collection: ^0.2
- alcamo/xml: ^0.1
Requires (Dev)
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: 3.*
README
use alcamo\xml_creation\{
Comment,
DoctypeDecl,
Element,
Nodes,
ProcessingInstruction,
Raw,
XmlDecl
};
include $_composer_autoload_path ?? __DIR__ . '/../vendor/autoload.php';
$xml = new Nodes(
new XmlDecl(),
new DoctypeDecl(
'foo',
'SYSTEM "foo.dtd"',
'<!ATTLIST bar id ID #IMPLIED>'
),
new ProcessingInstruction(
'xml-stylesheet',
'href="xsl/foo.xsl" type="text/xsl"'
),
new Element(
'foo',
[ 'xml:lang' => 'is' ],
[
new Comment(' Lorem ipsum dolor. '),
new Element(
'bar',
[ 'id' => 'my-bar' ],
'sed diam <nonumy> eirmod tempor'
),
new Raw('<baz>consetetur sadipscing elitr</baz>')
]
)
);
Nodes::setFormatOutput(true);
echo $xml . PHP_EOL;
Nodes::setFormatOutput(false);
echo $xml . PHP_EOL;
This example is contained in this package as a file in the bin
directory. It will output
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo SYSTEM "foo.dtd" [ <!ATTLIST bar id ID #IMPLIED> ]>
<?xml-stylesheet href="xsl/foo.xsl" type="text/xsl"?>
<foo xml:lang="is">
<!-- Lorem ipsum & dolor. -->
<bar id="my-bar">sed diam <nonumy> eirmod tempor</bar>
<baz>consetetur sadipscing elitr</baz>
</foo>
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE foo SYSTEM "foo.dtd" [ <!ATTLIST bar id ID #IMPLIED> ]><?xml-stylesheet href="xsl/foo.xsl" type="text/xsl"?><foo xml:lang="is"><!-- Lorem ipsum & dolor. --><bar id="my-bar">sed diam <nonumy> eirmod tempor</bar><baz>consetetur sadipscing elitr</baz></foo>
See the doxygen documentation for details.