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.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.