--- gnumeric/plugins/openoffice/openoffice-read.c	2005-09-28 15:59:50.000000000 -0300
+++ gnumeric/plugins/openoffice/openoffice-read.c	2005-09-30 13:12:19.056740384 -0300
@@ -65,6 +65,8 @@ GNM_PLUGIN_MODULE_HEADER;
 #define OPENOFFICEORG1 0
 #define OPENDOCUMENT 1
 
+#define OPENDOCUMENT_HEADER_FORMULA "oooc:"
+
 typedef enum {
 	OO_STYLE_UNKNOWN,
 	OO_STYLE_CELL,
@@ -260,7 +262,7 @@ oo_parse_distance (OOParseState *state, 
 		} else if (0 == strncmp (end, "mi", 2)) {
 			num = GO_IN_TO_PT (num*63360.);
 			end += 2;
-		} else if (0 == strncmp (end, "inch", 4)) {
+		} else if ((0 == strncmp (end, "inch", 4)) || (0 == strncmp (end, "in", 2))) {
 			num = GO_IN_TO_PT (num);
 			end += 4;
 		} else {
@@ -552,7 +554,12 @@ oo_cell_start (GsfXMLIn *xin, xmlChar co
 				oo_warning (state, _("Missing expression"));
 				continue;
 			}
-			expr_string = gnm_expr_char_start_p (attrs[1]);
+			/* support OpenDocument using OPENDOCUMENT_HEADER_FORMULA */
+			if(!strncmp(attrs[1], OPENDOCUMENT_HEADER_FORMULA, strlen(OPENDOCUMENT_HEADER_FORMULA)))
+				expr_string = gnm_expr_char_start_p (&attrs[1][strlen(OPENDOCUMENT_HEADER_FORMULA)]);
+			else
+				expr_string = gnm_expr_char_start_p (attrs[1]);
+
 			if (expr_string == NULL)
 				oo_warning (state, _("Expression '%s' does not start with a recognized character"), attrs[1]);
 			else if (*expr_string == '\0')
@@ -574,7 +581,9 @@ oo_cell_start (GsfXMLIn *xin, xmlChar co
 			}
 		} else if (oo_attr_bool (state, attrs, OO_NS_TABLE, "boolean-value", &bool_val))
 			val = value_new_bool (bool_val);
-		else if (gsf_xml_in_namecmp (xin, attrs[0], OO_NS_TABLE, "date-value")) {
+		/* support OpenDocument using OO_NS_OFFICE */
+		else if ((gsf_xml_in_namecmp (xin, attrs[0], OO_NS_TABLE, "date-value")) ||
+				(gsf_xml_in_namecmp (xin, attrs[0], OO_NS_OFFICE, "date-value"))) {
 			unsigned y, m, d, h, mi;
 			float s;
 			unsigned n = sscanf (attrs[1], "%u-%u-%uT%u:%u:%g",
@@ -599,7 +608,9 @@ oo_cell_start (GsfXMLIn *xin, xmlChar co
 				val = value_new_float (h + ((double)m / 60.) + ((double)s / 3600.));
 		} else if (gsf_xml_in_namecmp (xin, attrs[0], OO_NS_TABLE, "string-value"))
 			val = value_new_string (attrs[1]);
-		else if (oo_attr_float (state, attrs, OO_NS_TABLE, "value", &float_val))
+		/* support OpenDocument using OO_NS_OFFICE */
+		else if ((oo_attr_float (state, attrs, OO_NS_TABLE, "value", &float_val)) ||
+				(oo_attr_float (state, attrs, OO_NS_OFFICE, "value", &float_val)))
 			val = value_new_float (float_val);
 		else if (oo_attr_int (state, attrs, OO_NS_TABLE, "number-matrix-columns-spanned", &array_cols))
 			;
@@ -1378,6 +1389,102 @@ GSF_XML_IN_NODE (START, OFFICE, OO_NS_OF
 };
 
 /****************************************************************************/
+/* Generated based on:
+ * http://www.oasis-open.org/committees/download.php/12572/OpenDocument-v1.0-os.pdf */
+static GsfXMLInNode opendocument_content_dtd[] = {
+	GSF_XML_IN_NODE_FULL (START, START, -1, NULL, FALSE, FALSE, TRUE, NULL, NULL, 0),
+	GSF_XML_IN_NODE (START, OFFICE, OO_NS_OFFICE, "document-content", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE, SCRIPT, OO_NS_OFFICE, "scripts", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE, OFFICE_FONTS, OO_NS_OFFICE, "font-face-decls", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE_FONTS, FONT_FACE, OO_NS_STYLE, "font-face", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE, OFFICE_STYLES, OO_NS_OFFICE, "automatic-styles", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE_STYLES, STYLE, OO_NS_STYLE, "style", FALSE, &oo_style, &oo_style_end),
+	GSF_XML_IN_NODE (STYLE, TABLE_COL_PROPS, OO_NS_STYLE, "table-column-properties", FALSE, &oo_style_prop, NULL),
+	GSF_XML_IN_NODE (STYLE, TABLE_ROW_PROPS, OO_NS_STYLE, "table-row-properties", FALSE, &oo_style_prop, NULL),
+	GSF_XML_IN_NODE (STYLE, TABLE_PROPS, OO_NS_STYLE, "table-properties", FALSE, &oo_style_prop, NULL),
+
+	GSF_XML_IN_NODE (OFFICE_STYLES, NUMBER_STYLE, OO_NS_NUMBER, "number-style", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (NUMBER_STYLE, NUMBER_STYLE_NUMBER, OO_NS_NUMBER,	  "number", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (NUMBER_STYLE, NUMBER_STYLE_TEXT, OO_NS_NUMBER,	  "text", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (NUMBER_STYLE, NUMBER_STYLE_FRACTION, OO_NS_NUMBER, "fraction", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (NUMBER_STYLE, NUMBER_SCI_STYLE_PROP, OO_NS_NUMBER, "scientific-number", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (NUMBER_STYLE, NUMBER_STYLE_PROP, OO_NS_STYLE,	  "properties", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (NUMBER_STYLE, NUMBER_MAP, OO_NS_STYLE,		  "map", FALSE, NULL, NULL),
+
+	GSF_XML_IN_NODE (OFFICE_STYLES, DATE_STYLE, OO_NS_NUMBER, "date-style", FALSE, &oo_date_style, &oo_date_style_end),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_DAY, OO_NS_NUMBER,		"day", FALSE,	&oo_date_day, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_MONTH, OO_NS_NUMBER,		"month", FALSE,	&oo_date_month, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_YEAR, OO_NS_NUMBER,		"year", FALSE,	&oo_date_year, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_ERA, OO_NS_NUMBER,		"era", FALSE,	&oo_date_era, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_DAY_OF_WEEK, OO_NS_NUMBER,	"day-of-week", FALSE, &oo_date_day_of_week, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_WEEK_OF_YEAR, OO_NS_NUMBER,	"week-of-year", FALSE, &oo_date_week_of_year, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_QUARTER, OO_NS_NUMBER,		"quarter", FALSE, &oo_date_quarter, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_HOURS, OO_NS_NUMBER,		"hours", FALSE,	&oo_date_hours, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_MINUTES, OO_NS_NUMBER,		"minutes", FALSE, &oo_date_minutes, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_SECONDS, OO_NS_NUMBER,		"seconds", FALSE, &oo_date_seconds, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_AM_PM, OO_NS_NUMBER,		"am-pm", FALSE,	&oo_date_am_pm, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_TEXT, OO_NS_NUMBER,		"text", TRUE,	NULL, &oo_date_text_end),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_TEXT_PROP, OO_NS_STYLE,		"text-properties", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (DATE_STYLE, DATE_MAP, OO_NS_STYLE,		"map", FALSE, NULL, NULL),
+
+	GSF_XML_IN_NODE (OFFICE_STYLES, TIME_STYLE, OO_NS_NUMBER, "time-style", FALSE, &oo_date_style, &oo_date_style_end),
+	GSF_XML_IN_NODE (TIME_STYLE, TIME_HOURS, OO_NS_NUMBER,		"hours", FALSE,	&oo_date_hours, NULL),
+	GSF_XML_IN_NODE (TIME_STYLE, TIME_MINUTES, OO_NS_NUMBER,		"minutes", FALSE, &oo_date_minutes, NULL),
+	GSF_XML_IN_NODE (TIME_STYLE, TIME_SECONDS, OO_NS_NUMBER,		"seconds", FALSE, &oo_date_seconds, NULL),
+	GSF_XML_IN_NODE (TIME_STYLE, TIME_AM_PM, OO_NS_NUMBER,		"am-pm", FALSE,	&oo_date_am_pm, NULL),
+	GSF_XML_IN_NODE (TIME_STYLE, TIME_TEXT, OO_NS_NUMBER, 		"text", TRUE,	NULL, &oo_date_text_end),
+	GSF_XML_IN_NODE (TIME_STYLE, TIME_TEXT_PROP, OO_NS_STYLE,		"text-properties", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (TIME_STYLE, TIME_MAP, OO_NS_STYLE,		"map", FALSE, NULL, NULL),
+
+	GSF_XML_IN_NODE (OFFICE_STYLES, STYLE_BOOL, OO_NS_NUMBER, "boolean-style", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_BOOL, BOOL_PROP, OO_NS_NUMBER, "boolean", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE_STYLES, STYLE_CURRENCY, OO_NS_NUMBER, "currency-style", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_CURRENCY, CURRENCY_STYLE, OO_NS_NUMBER, "number", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_CURRENCY, CURRENCY_STYLE_PROP, OO_NS_STYLE, "properties", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_CURRENCY, CURRENCY_MAP, OO_NS_STYLE, "map", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_CURRENCY, CURRENCY_SYMBOL, OO_NS_NUMBER, "currency-symbol", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_CURRENCY, CURRENCY_TEXT, OO_NS_NUMBER, "text", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE_STYLES, STYLE_PERCENTAGE, OO_NS_NUMBER, "percentage-style", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_PERCENTAGE, PERCENTAGE_STYLE_PROP, OO_NS_NUMBER, "number", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_PERCENTAGE, PERCENTAGE_TEXT, OO_NS_NUMBER, "text", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE_STYLES, STYLE_TEXT, OO_NS_NUMBER, "text-style", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_TEXT, STYLE_TEXT_CONTENT, OO_NS_NUMBER,	"text-content", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_TEXT, STYLE_TEXT_PROP, OO_NS_NUMBER,		"text", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (STYLE_TEXT, STYLE_TEXT_MAP, OO_NS_STYLE,		"map", FALSE, NULL, NULL),
+
+	GSF_XML_IN_NODE (OFFICE, OFFICE_BODY, OO_NS_OFFICE, "body", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (OFFICE_BODY, TABLE_SETTINGS, OO_NS_OFFICE, "spreadsheet", FALSE, NULL, NULL),
+
+	GSF_XML_IN_NODE (TABLE_SETTINGS, TABLE, OO_NS_TABLE, "table", FALSE, &oo_table_start, NULL),
+	GSF_XML_IN_NODE (TABLE, FORMS, OO_NS_OFFICE, "forms", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (TABLE, TABLE_COL, OO_NS_TABLE, "table-column", FALSE, &oo_col_start, NULL),
+	GSF_XML_IN_NODE (TABLE, TABLE_ROW, OO_NS_TABLE, "table-row", FALSE, &oo_row_start, NULL),
+	GSF_XML_IN_NODE (TABLE_ROW, TABLE_CELL, OO_NS_TABLE, "table-cell", FALSE, &oo_cell_start, &oo_cell_end),
+	GSF_XML_IN_NODE (TABLE_ROW, TABLE_COVERED_CELL, OO_NS_TABLE, "covered-table-cell", FALSE, &oo_covered_cell_start, &oo_covered_cell_end),
+	GSF_XML_IN_NODE (TABLE_CELL, CELL_TEXT, OO_NS_TEXT, "p", TRUE, NULL, &oo_cell_content_end),
+	GSF_XML_IN_NODE (CELL_TEXT, CELL_TEXT_S,    OO_NS_TEXT, "s", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (CELL_TEXT, CELL_TEXT_SPAN, OO_NS_TEXT, "span", GSF_XML_SHARED_CONTENT, &oo_cell_content_span_start, &oo_cell_content_span_end),
+	GSF_XML_IN_NODE (TABLE_CELL, CELL_OBJECT, OO_NS_DRAW, "object", FALSE, NULL, NULL),		/* ignore for now */
+	GSF_XML_IN_NODE (TABLE_CELL, CELL_GRAPHIC, OO_NS_DRAW, "g", FALSE, NULL, NULL),		/* ignore for now */
+	GSF_XML_IN_NODE (CELL_GRAPHIC, CELL_GRAPHIC, OO_NS_DRAW, "g", FALSE, NULL, NULL),		/* 2nd def */
+	GSF_XML_IN_NODE (CELL_GRAPHIC, DRAW_POLYLINE, OO_NS_DRAW, "polyline", FALSE, NULL, NULL),	/* 2nd def */
+	GSF_XML_IN_NODE (TABLE, TABLE_COL_GROUP, OO_NS_TABLE, "table-column-group", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (TABLE_COL_GROUP, TABLE_COL_GROUP, OO_NS_TABLE, "table-column-group", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (TABLE_COL_GROUP, TABLE_COL, OO_NS_TABLE, "table-column", FALSE, NULL, NULL), /* 2nd def */
+	GSF_XML_IN_NODE (TABLE_ROW_GROUP, TABLE_ROW_GROUP, OO_NS_TABLE, "table-row-group", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (TABLE, TABLE_ROW_GROUP,	      OO_NS_TABLE, "table-row-group", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (TABLE_ROW_GROUP, TABLE_ROW,	    OO_NS_TABLE, "table-row", FALSE, NULL, NULL), /* 2nd def */
+	GSF_XML_IN_NODE (OFFICE_BODY, NAMED_EXPRS, OO_NS_TABLE, "named-expressions", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (NAMED_EXPRS, NAMED_EXPR, OO_NS_TABLE, "named-expression", FALSE, &oo_named_expr, NULL),
+	GSF_XML_IN_NODE (OFFICE_BODY, DB_RANGES, OO_NS_TABLE, "database-ranges", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (DB_RANGES, DB_RANGE, OO_NS_TABLE, "database-range", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (DB_RANGE, TABLE_SORT, OO_NS_TABLE, "sort", FALSE, NULL, NULL),
+	GSF_XML_IN_NODE (TABLE_SORT, SORT_BY, OO_NS_TABLE, "sort-by", FALSE, NULL, NULL),
+	{ NULL }
+};
+
+/****************************************************************************/
+
 
 static GnmExpr const *
 errortype_renamer (char const *name, GnmExprList *args, GnmExprConventions *convs)
@@ -1427,6 +1534,7 @@ oo_conventions (void)
 }
 
 static GsfXMLInDoc *content_doc, *settings_doc, *styles_doc;
+static GsfXMLInDoc *content_opendocument;
 
 void
 openoffice_file_open (GOFileOpener const *fo, IOContext *io_context,
@@ -1542,7 +1650,11 @@ openoffice_file_open (GOFileOpener const
 		g_object_unref (styles);
 	}
 
-	state.base.doc = content_doc;
+	if (filter == OPENOFFICEORG1)
+		state.base.doc = content_doc;
+	else if (filter == OPENDOCUMENT)
+		state.base.doc = content_opendocument;
+
 	if (gsf_xml_in_parse (&state.base, content)) {
 		GsfInput *settings;
 
@@ -1590,6 +1702,7 @@ go_plugin_init (GOPlugin *plugin, GOCmdC
 	styles_doc   = gsf_xml_in_doc_new (opencalc_styles_dtd, ooo_ns);
 	content_doc  = gsf_xml_in_doc_new (opencalc_content_dtd, ooo_ns);
 	settings_doc = gsf_xml_in_doc_new (opencalc_settings_dtd, ooo_ns);
+	content_opendocument  = gsf_xml_in_doc_new (opendocument_content_dtd, ooo_ns);
 	load_opendocument_meta();
 }
 G_MODULE_EXPORT void
@@ -1598,5 +1711,6 @@ go_plugin_shutdown (GOPlugin *plugin, GO
 	gsf_xml_in_doc_free (styles_doc);
 	gsf_xml_in_doc_free (content_doc);
 	gsf_xml_in_doc_free (settings_doc);
+	gsf_xml_in_doc_free (content_opendocument);
 	free_opendocument_meta();
 }
