wordpress hit counter
Reading and Writing OOXML Metadata with iOS and Objective-C - OpenXML Developer - Blog - OpenXML Developer
Goodbye and Hello

OpenXmlDeveloper.org is Shutting Down

There is a time for all good things to come to an end, and the time has come to shut down OpenXmlDeveloper.org.

Screen-casts and blog posts: Content on OpenXmlDeveloper.org will be moving to EricWhite.com.

Forums: We are moving the forums to EricWhite.com and StackOverflow.com. Please do not post in the forums on OpenXmlDeveloper.org. Instead, please post in the forums at EricWhite.com or at StackOverflow.com.

Please see this blog post for more information about my plans moving forward.  Cheers, Eric

Reading and Writing OOXML Metadata with iOS and Objective-C

Reading and Writing OOXML Metadata with iOS and Objective-C

  • Comments 6

By Martin Holman

This tutorial will show how to access and display the Dublin Core properties of any OpenXML document. This could quite easily be extended to access any other sections of the OpenXML format.

Right let’s get started! Fire up XCode.

 

Create a window-based iPhone application as shown

Here we are with our default project

 

First up we will need a couple of third party libraries for interacting with zip files and XML data. The libraries we will be using are the GDataXML[1] library for reading the XML properties contained in the OpenXML file format, and Objective-Zip[2] for opening the OpenXML files and gaining access to the XML documents contained within. Feel free to substitute your favourite XML and ZIP libraries for iOS.

We need to copy the required files from these libraries into our project. Make a folder to hold the XML library and copy the GDataXMLNode class and header file to it, like so

 

 

Then we need to copy all of the ZIP class files to the project and put them in a ZIP folder, like so

 

 

The last bit of setup we need to do is include a OOXML document in our project to pull the values out of. Create one yourself in Word or grab one from someone else.

 

 

Next up we need to use the zip library to expand the OpenXML file and retrieve the files we want to use. This is done by creating a ZipFile object in unzip mode with our OpenXML document. We then locate the file with the Dublin Core properties in it and read out the xml file from the zip archive.

Then we need to create model classes to hold our representation of what is stored in the XML. I have created a OpenXMLDocument class and a OpenXMLDocumentProperty class to hold the values in.

First we create an instance of OpenXMLDocument to hold the OpenXMLDocumentProperty collection. We select all the child elements of the root element in the xml document we expanded above. This is our collection of Dublin Core properties. For each element we have we create an instance of OpenXMLDocumentProperty and add it to our collection stored on the OpenXMLDocument instance we created. We could also use XPath queries to select only the information that we required.

From here we only need to create a basic UI that enables us to download files and store them in a table for easy browsing of their properties. For now we will just print the properties to the console.

 

[1] http://code.google.com/p/gdata-objectivec-client/

[2] http://code.google.com/p/objective-zip/

 

Page 1 of 1 (6 items)