AKA:Â Sheets API access with PHP part 3
Continuing my series on using PHP to manipulate Google Spreadsheets, I’ve added a section to my code that reads the XML representation of a spreadsheet and then parses out the rows and columns. Â Note that whenever you’re working with list-based feeds, we’re assuming that the first row contains column headings.
Using SimpleXML, it wasn’t difficult to parse out the cell data. Â The biggest hurdle was learning about XML namespaces — at first, I thought that the XML had tags like “gd:etag” or “gsx:quantity” and had to learn that gd and gsx were namespaces. Â In SimpleXML, several of the methods take a namespace as a parameter. Â You can specify the prefix or namespace URL as described in the doc for the children method here.
I think it’s also possible to get the spreadsheet data as json, but I haven’t tried that yet.
Hey I don’t understand the namespace part. What is gsx in foreach ($entry->children(‘gsx’, TRUE) as $column) { ???
XML Namespaces are ways to make sure that element names don’t conflict with each other. I’m not an expert, and used trial and error to get the PHP tools to be able to “see” the parts of the XML that I wanted to extract or set.
Karl