0

My XML structure looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
 <Styles>
  <Style ss:ID="Default" ss:Name="Normal">
   <Alignment ss:Vertical="Bottom"/>
   <Borders/>
   <Font/>
   <Interior/>
   <NumberFormat/>
   <Protection/>
  </Style>
  <Style ss:ID="s63" ss:Name="Hyperlink">
   <Font ss:Color="#0563C1" ss:Underline="Single"/>
  </Style>
  <Style ss:ID="s27">
   <Font x:Family="Swiss" ss:Color="#0000FF" ss:Bold="1"/>
  </Style>
 </Styles>
 <Worksheet ss:Name="Sheet1">
  <ss:Table>
   <ss:Row>
    <ss:Cell ss:StyleID="s27">
     <ss:Data ss:Type="String">123</ss:Data>
    </ss:Cell>

What I want to do is loop through every ss:Row element and gather the attributes of ss:Cell as well as values of ss:Data.

If I try simply loading this XML string into SimpleXMLElement class, like this: $objects = new SimpleXMLElement($xmlString); , var dumping it skips the entire ss:Table node.

I have also tried parsing it with DOMDocument, but no luck there either. What is the proper way to achieve this?

Edit:

I did try the xpath solution like this:

foreach($objects->xpath('//ss:Row') as $row) {
            var_dump(count($row->xpath("//ss:Cell")));
            die();
        }

just to see if it was in fact selecting nodes under the current ss:Row parent node, but it turns out it was selecting all ss:Cell nodes in the entire document.

Zannix
  • 1,473
  • 3
  • 16
  • 26
  • 4
    Possible duplicate of [Parse XML with Namespace using SimpleXML](http://stackoverflow.com/questions/595946/parse-xml-with-namespace-using-simplexml) – Can O' Spam Nov 17 '15 at 11:17
  • Or dupe of: [Parse xml namespaces with php simplexml](http://stackoverflow.com/questions/16412047/parse-xml-namespaces-with-php-simplexml) – Can O' Spam Nov 17 '15 at 11:20

0 Answers0