I want to get attribut value type (ss:Name) from xml element with php. But it doesn't work.
This is my xml file :
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Worksheet ss:Name="097-097-024">
</Worksheet>
</Workbook>
and my php source
<?php
$xml = simplexml_load_file($fichier);
$attr = $xml->Worksheet->Workbook->attributes();
echo $attr['ss:Name'];
?>
Can you help my to get ss:Name value ?
Thanks
The prefix of your attribute ss is a namespace.
You can grab attributes for that namespace by requesting it as the argument for Attributes() like this:
$node->Attributes('urn:schemas-microsoft-com:office:spreadsheet');
$xml = '<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Worksheet ss:Name="097-097-024">
</Worksheet>
</Workbook>';
Example php:
<?php
$xml = simplexml_load_string($xml);
foreach($xml->Worksheet->Attributes('urn:schemas-microsoft-com:office:spreadsheet') as $key=>$val) {
echo "$key: $val\n";
}
outputs
Name: 097-097-024
also note that your top node is Worksheet not Worksheet->Workbook
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With