Repository navigation
Getting Started: 11. Importing
Daniele Orlando edited this page Aug 1, 2018
·
3 revisions
FluidXML provides an easy way to import existing XML documents from a variety of formats.
The resulting object is a FluidXml instance filled with the XML of the imported document.
-
XML String
$xml = <<<XML <?xml version="1.0" encoding="UTF-8"?> <html> <head/> <body/> </html> XML;
Concise syntax
$doc = fluidxml($xml);Extended syntax
$doc = new FluidXml($xml);
-
XML File
Concise syntax
$doc = fluidify('path/to/file.xml');Extended syntax
$doc = FluidXml::load('path/to/file.xml');
-
DOMDocument
Concise syntax
$doc = fluidxml($domdocument); // $domdocument is an instance of DOMDocument/DOMNodeList/DOMNode.Extended syntax
$doc = new FluidXml($domdocument); // $domdocument is an instance of DOMDocument/DOMNodeList/DOMNode.
-
SimpleXMLElement
Concise syntax
$doc = fluidxml($simplexml); // $simplexml is an instance of SimpleXMLElement.Extended syntax
$doc = new FluidXml($simplexml); // $simplexml is an instance of SimpleXMLElement.
Existing XML documents instances can be injected in any point of the FluidXML document.
$doc = fluidxml(); $doc->add($dom) // A DOMDocument/DOMNode/DOMNodeList instance. ->add($simplexml) // A SimpleXMLElement instance. ->add($fluidxml) // A FluidXml instance. ->add($fluidxml->query('//p')); // A FluidXml query instance.
Crazy things are possible too using arrays and I will not stop you from doing them.
$doc->add([ 'dom' => $dom, 'simple' => $simplexml, 'file' => fluidify('path/to/file.xml') ]);