I find myself in the situation of having to obtain the value of the "version" attribute of the XML file declaration, like so:
<?xml version="1.0" encoding="ISO-8859-1"?>
<TED_EXPORT DOC_ID="000002-2019">
<TECHNICAL_SECTION>
<RECEPTION_ID>18-587627-001</RECEPTION_ID>
<DELETION_DATE>20190331</DELETION_DATE>
<FORM_LG_LIST>DA DE EN ES FI FR EL IT NL PT SV CS ET HU LT LV MT PL SK SL GA BG RO HR </FORM_LG_LIST>
<COMMENTS>From Convertor</COMMENTS>
</TECHNICAL_SECTION>
....
I am testing with SimpleXML but when loading the file, what is captured at the start is always from the first tag, so I cannot access the version field.
$xml = simplexml_load_file("xml/test.xml");
/* DOC ID */
$atributos = $xml->attributes();
echo $atributos->DOC_ID;
And this is the result that comes out of print_r(xml)
SimpleXMLElement Object
(
[@attributes] => Array
(
[VERSION] => R2.0.9.S03.E01
[DOC_ID] => 000001-2019
[EDITION] => 2019001
)
[TECHNICAL_SECTION] => SimpleXMLElement Object
(
[RECEPTION_ID] => 18-583998-001
[DELETION_DATE] => 20190207
[FORM_LG_LIST] => DA DE EN ES FI FR EL IT NL PT SV CS ET HU LT LV MT PL SK SL GA BG RO HR
[COMMENTS] => From Convertor
)
The problem is that
SimpleXML
it doesn't create an XML object itself. Looking through the documentation it doesn't seem to have any properties or methods to access the version of the document itself.You can instead use
DOMDocument
, which does work with an XML object as such and therefore has a propertyxmlVersion
that saves the version of the object when it is created.For example:
It goes without saying that reading any other part of the XML is also possible with
DOMDocument
.