Re: [PHP] Re: SimpleXML & libxml options (XInclude)



Rob wrote:
Ben Roberts wrote:

I'm trying to get the SimpleXML extension to read an XML file and process the XInclude statements within the XML file.

The SimpleXML docs state that libxml options may be specified using the predefined constants that are available when PHP is compiled with libxml support (as it is when you use SimpleXML).
http://uk2.php.net/manual/en/function.simplexml-element-construct.php

LIBMLXML_XINLCUDE currently only works with XMLReader.

You would need to import your doc to DOM and then processes the xinclude:

$xml_file = './master.xml';

$xml = new SimpleXMLElement($xml_file, 0, true);
$dom = dom_import_simplexml($xml);
$dom->ownerDocument->xinclude();
print_r($xml);

Rob


Thanks Rob. That works. And it appears to work flawlessly if you subsequently convert it back to a SimpleXML object too:

$xml = new SimpleXMLElement($xml_file, 0, true);

$dom = dom_import_simplexml($xml);
$dom->ownerDocument->xinclude();

$xml = simplexml_import_dom($dom);
Dump($xml);


I have to convert it back to the SimpleXML object as I have an existing application that relies on the SimpleXML structure.

Is it likely that this will be supported directly by SimpleXML in future versions of PHP?

Ben
.



Relevant Pages

  • Re: reading a XML file on every page execution - convert to PHP?
    ... into a simpleXML node every time index.php loads. ... Including a php file requires the file be read then parsed. ... modification date- and use the .xml only if it was newer. ... cannot load, ...
    (comp.lang.php)
  • Re: How to open and read "feed:" in PHP?
    ... Question: Is a URL that starts with feed: output XML? ... Question: How do I open a feed: URL in PHP and parse it? ... I looked at the example for simpleXML on the php.net web site. ... That's because SimpleXML alows you to navigate the xml tree as you wish, foroward and backwards how many times you like. ...
    (comp.lang.php)
  • Re: Interaction between SimpleXML & DOM
    ... The above is not well-formed XML. ... Give up using SimpleXML and use DOM for everything... ... $contentDOM = new DOMDocument; ...
    (comp.lang.php)
  • Re: How to open and read "feed:" in PHP?
    ... Question: Is a URL that starts with feed: output XML? ... Question: How do I open a feed: URL in PHP and parse it? ... Now you have a SimpleXML object named $rss which you can use to iterate. ... SimpleXML alows you to navigate the xml tree as you wish, ...
    (comp.lang.php)
  • SimpleXML & libxml options (XInclude)
    ... I'm trying to get the SimpleXML extension to read an XML file and process the XInclude statements within the XML file. ... The SimpleXML docs state that libxml options may be specified using the predefined constants that are available when PHP is compiled with libxml support. ... So, looking at the libxml options, I see there is a predefined constant LIBXML_XINCLUDE which when specified should implement XInclude substitution. ...
    (php.general)