SimpleXML & libxml options (XInclude)




Hi there. I'm hoping someone can help me with what I think might be a slightly obscure problem.

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

So, looking at the libxml options, I see there is a predefined constant LIBXML_XINCLUDE which when specified should implement XInclude substitution. So my SimpleXML object I define as follows:

$xml_file = './master.xml';

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

print_r($xml);

Viewing the resulting datastructure shows me that it has not honoured the request to implement the XInclude directives.

Does anyone know if a) I'm using the correct syntax for this, and b) have any experience of getting this working.

My master.xml file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xi="http://www.w3.org/2001/XInclude";>
<foo>ssd</foo>
<bar>sss</bar>
<xi:include href="a.xml">
<xi:fallback>
<error>xinclude - a.xml not found</error>
</xi:fallback>
</xi:include>
</root>

and then I have a.xml which looks like:

<?xml version="1.0" encoding="UTF-8"?>
<a_root>
<oranges>test</oranges>
<apples>test more</apples>
</a_root>

I'm running PHP 5.1.5 with libxml 2.6.20 on Fedora Core 4 linux.

Cheers

Ben
.



Relevant Pages

  • Re: [PHP] Re: SimpleXML & libxml options (XInclude)
    ... 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. ...
    (php.general)
  • reading a XML file on every page execution - convert to PHP?
    ... into a simpleXML node every time index.php loads. ... The simplest thing to do would be to serialize the xml file into ... include the .php file, de-serialize the simplexml object and go, ... If file A requires file B, and file B cannot load, file A suffers ...
    (comp.lang.php)
  • Problem with "undefined entities" using DOM
    ... I have a problem with both DOM and SimpleXML. ... I'm reading an XML file ... HOW CAN I AVOID those warnings??? ...
    (comp.lang.php)
  • Using SimpleXML
    ... Manually parse the XML file ... done with SimpleXML? ... Hugh ... Prev by Date: ...
    (comp.lang.php)
  • Re: simplexml and CDATA
    ... element when parsing an xml file or string with simplexml. ... CDATA and what simplexml does. ... In CDATA sections, you can include e.g. ...
    (comp.lang.php)