Calc: how to export to xml

Is there a way to export a spreadsheet from calc tom xml according to an .xsd scheme?

thanks

EDIT 2013-06-15

(moved the second comment by @vergna to the original question)

xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xsd:include schemaLocation="TypesL190.xsd"/>	
	<xsd:element name="indici">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="metadata">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="titolo" type="xsd:string"/>
							<xsd:element name="abstract" type="xsd:string"/>
							<xsd:element name="dataPubblicazioneIndice" type="xsd:date" nillabl

I don’t understand your question. Can you please elaborate? ODF is defined by a schema and is in XML. An XML Schema Definition (XSD) as the name suggests is simply any such definition, for example here are some OOXML Strict XSDs used for testing LO. Are you referring to Extensible Stylesheet Language Transformation (XSLT) filters for converting ODS to a different XML schema?

I have a spreadsheet that is to be exported in xml according to a precise pattern

Thanks for the example. Is it possible to post a link to the entire XSD? Surround the link text with square brackets in your comment and follow it immediately with the url in round brackets. The bit shown is only really the header info and does not cover the data. I will provide an answer, but will need to come back and edit it for clarity.

http://dati.avcp.it/schema/datasetAppaltiL190.xsd

Thanks for providing the entire XSD. I have updated my answer to give an example of how to go about creating an XSLT based on your XSD.

Generally the way to get data into and out of LibreOffice in the manner you are indicating is via an Extensible Stylesheet Language Transformation (XSLT) filter. While this requires an understanding of the XML Schema Definition (XSD) of the sending and receiving formats, it does not explicitly reference the XSD. This OO Forum thread gives a decent example of the type of import and export XSLT filter that is required to convert data in a foreign XML structure to and from Calc XML.

The Tools > XML Filter Settings… menu is where these types of filters are designed and recorded. Help page is here.

I am going to expand my original answer to give a very basic outline of what it is you require. You have a Calc spreadsheet, which stores data (e.g., A1=123abc) in XML (the content.xml file) like this:

<office:spreadsheet>
	<table:table table:name="Sheet1" table:style-name="ta1">
		<table:table-column table:style-name="co1" table:default-cell-style-name="Default"/>
			<table:table-row table:style-name="ro1">
				<table:table-cell office:value-type="string">
					<text:p>123abc</text:p>
				</table:table-cell>
			</table:table-row>
		</table:table>
	<table:named-expressions/>
</office:spreadsheet>

You need to take this data structure (and the data within it) and turn it into your particular XML data structure, which is defined by an XSD (datasetAppaltiL190.xsd). This XSD has a data element, which is likely where the data from the ODS needs to be mapped to, defined as:

<xsd:element name="data">
	<xsd:complexType>
		<xsd:sequence>
			<xsd:element name="lotto" minOccurs="0" maxOccurs="unbounded">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="cig" type="legge190:CigType" nillable="false"/>
						<xsd:element name="strutturaProponente" nillable="false">
							<xsd:complexType>
								<xsd:sequence>
									<xsd:element name="codiceFiscaleProp" type="legge190:codiceFiscaleType" nillable="false"/>
									<xsd:element name="denominazione" type="legge190:denominazioneType" nillable="false"/>
								</xsd:sequence>
							</xsd:complexType>
						</xsd:element>
						<xsd:element name="oggetto" type="legge190:oggettoType" nillable="false"/>
						<xsd:element name="sceltaContraente" type="legge190:sceltaContraenteType" nillable="false"/>
						<xsd:element name="partecipanti">
							<xsd:complexType>
								<xsd:sequence>
									<xsd:element name="raggruppamento" minOccurs="0" maxOccurs="unbounded">
										<xsd:complexType>
											<xsd:sequence>
												<xsd:element name="membro" type="legge190:aggregatoType" minOccurs="2" maxOccurs="unbounded"/>
											</xsd:sequence>
										</xsd:complexType>
									</xsd:element>
									<xsd:element name="partecipante" type="legge190:singoloType" minOccurs="0" maxOccurs="unbounded"/>
								</xsd:sequence>
							</xsd:complexType>
						</xsd:element>
						... etc ...
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:sequence>
	</xsd:complexType>
</xsd:element>

That is not the actual data, but rather a definition of how the data should be structured. The actual data in the resultant XML, based on the above definition, will look something like:

<data>
	<lotto>
		<cig></cig>
		<strutturaProponente>
			<codiceFiscaleProp></codiceFiscaleProp>
			<denominazione></denominazione>
		</strutturaProponente>
		<oggetto></oggetto>
		<sceltaContraente>
			<codiceFiscaleProp></codiceFiscaleProp>
			<denominazione></denominazione>
			<partecipanti>
				<raggruppamento>
					<membro></membro>
					<membro></membro>
					... etc ...
				</raggruppamento>
				<partecipante></partecipante>
				<partecipante></partecipante>
					... etc ...
				<raggruppamento>
					... etc ...
				</raggruppamento>
			</partecipanti>
		</sceltaContraente>
	</lotto>
	<lotto>
		... etc ...
	</lotto>
</data>

Furthermore, the data type for each XML element (e.g., <cig>) is defined in a separate XSD (TypesL190.xsd) that is referenced by the main XSD. In this secondary XSD, the CigType data type for the <cig> element is defined as:

<xsd:simpleType name="CigType">
	<xsd:restriction base="xsd:string">
		<xsd:maxLength value="10"/>
	</xsd:restriction>
</xsd:simpleType>

… in other words a string of up to 10 characters. In order to map the data in cell A1 of the ODS to the <cig> element in the output XML you will need to write an XSLT that includes code something like:

<xsl:template match="table:table">
	<xsl:for-each select="table:table-row">
		<xsl:if test="position()=1">
			<data>
				<lotto>
					<!-- Process the lotto data -->
					<xsl:for-each select="table:table-cell">
						<xsl:choose>
							<xsl:when test="position()=1">
							<cig><xsl:value-of select="text:p"/></cig>
							</xsl:when>
							<xsl:when test="position()=2">
								<strutturaProponente>
								<!-- Process the strutturaProponente data -->

Note that this is a very basic (and possibly not perfectly accurate) example based on what was demonstrated in the OO Forum link I provided above. You will need to determine the valid structure according to the XSD definitions. The logic to build valid output XML will need to be carefully written into the XSLT. There are probably XML tools that can assist in this process, but I cannot recommend any as I have not used any.