We are trying to export an excel table with "Denormalized Data" to xml. The table headers are as follows:
| AssetManager Code | AssetManager Date | Portfolio Code | Portfolio Name | MarketValue | NetCashFlow | Field | Field Code | Field Name |
The AssetManager Code and AssetManager Date are the same throughout, the rest of the columns contain variable data.
Here is an example of the xml output we want:
<AssetManager Code="PFM" Date="20130117">
<Portfolios>
<Portfolio Code="CC PSP" Name="Consilium Capital">
<MarketValue>5548056.51</MarketValue>
<NetCashFlow>0</NetCashFlow>
<UserFields>
<Field Code="AM UCGT" Name="AM daily Unrealised CG">4375</Field>
</UserFields>
</Portfolio>
<Portfolio Code="MM (FC)" Name="Money Market UT (FC)">
<MarketValue>28975149.6500735</MarketValue>
<NetCashFlow>0</NetCashFlow>
<UserFields>
<Field Code="UCGT" Name="AM daily Unrealised CG">0</Field>
</UserFields>
</Portfolio>
</Portfolios>
</AssetManager>
And our xsd file containing the mappings:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="AssetManager">
<xs:complexType>
<xs:sequence>
<xs:element ref="Portfolios" />
</xs:sequence>
<xs:attribute name="Code" type="xs:string"/>
<xs:attribute name="Date" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:complexType name="FieldType">
<xs:simpleContent>
<xs:extension base="xs:decimal">
<xs:attribute name="Code" type="xs:string"/>
<xs:attribute name="Name" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:element name="Portfolios">
<xs:complexType>
<xs:sequence>
<xs:element name="Portfolio">
<xs:complexType>
<xs:sequence>
<xs:element name="MarketValue" type="xs:decimal"/>
<xs:element name="NetCashFlow" type="xs:decimal"/>
<xs:element name="UserFields">
<xs:complexType>
<xs:sequence>
<xs:element name="Field" type="FieldType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="Code" type="xs:string"/>
<xs:attribute name="Name" type="xs:string"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
At the very least we'd like to know why excel considers data denormalised?
Any help will be much appreciated.
I wrote up some code to write a pivot table to a primitive XML format. Here I am not following any pre-set schema, just writing the pivot table heirarchy to XML. For this to work, you must use the outline form but not-compact (each new level should start a new column). Also the code expects no subtotals or grand totals, and only one level of numeric data in the data field is expected.
Your PT will be in an acceptable XML format with nodes named according to the PT headers, but the sub group titles come out as attributes unhelpfully named 'name ='. So you get XML that reads like - "Folder contents here".
See code below: one other caveat, this has not been cleaned up very well. there are some lines that will never get hit from old implementations of the code. Also, there is a stop right before the end for debugging - in case you need to make a change to the output and redo the file writing steps. Output is written as a text file named 'txt.txt' in the C: drive.
Edit and re-use as needed.
First of all, you have a problem with the posted XSD. The Portfolio should have the maxOccurs set to a value greater than 1 - otherwise you're not matching the sample XML and you wouldn't get the "denormalized data" error when verifying your map in Excel.
This article should explain common errors you get with Excel maps - yours included.
I guess what you did was to drag-drop the root - this will not work with repeating elements.
You may get around with what I did below; it may not work for your concrete example, but it should give you an idea.
Modified your XSD to account for repeating particles:
Drag the Code and Date only on the first sheet; rename that to something else if you want.
Drag Portfolios to another sheet.
Fill in some data and Export; this is what I got:
It looks pretty close. It should help you move forward if not with the solution itself, then with your investigations.