xmlcsvxsdmap-force

How create XML using CSV and XSD files?


I'm trying to map combined data of two csv-files to XML using MapForce.

This is my input:

Page;Project;Index
PageA;ProjectA;3
PageB;ProjectA;5
PageC;ProjectB;7

and

Subpage;Page;File
Subpage1;PageA;1.jpg
Subpage2;PageA;2.jpg
Subpage3;PageC;3.jpg

MapForce created a XSD based on my example of wanted output:

XML:

<Pages>
    <Page Title="PageA">
        <Template Name="PageTemplate">
            <Field Name="Context">ProjectA</Field>
            <Field Name="Index">3</Field>
        </Template>
        <Template Name="ShowSubpagesTemplate">
        </Template>
        <Template Name="SubpageTemplate">
            <Field Name="Subpage">Subpage1</Field>
            <Field Name="File">1.jpg</Field>
        </Template>     
        <Template Name="SubpageTemplate">
            <Field Name="Subpage">Subpage2</Field>
            <Field Name="File">2.jpg</Field>
        </Template>             
    </Page>
    <Page Title="PageB">
        <Template Name="PageTemplate">
            <Field Name="Context">ProjectA</Field>
            <Field Name="Index">5</Field>
        </Template>
        <Template Name="ShowSubpagesTemplate">
        </Template>
    </Page>
    <Page Title="PageC">
        <Template Name="PageTemplate">
            <Field Name="Context">ProjectB</Field>
            <Field Name="Index">7</Field>
        </Template>
        <Template Name="ShowSubpagesTemplate">
        </Template>
        <Template Name="SubpageTemplate">
            <Field Name="Subpage">Subpage3</Field>
            <Field Name="File">3.jpg</Field>
        </Template>             
    </Page>
</Pages>

XSD:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="Pages">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="Page" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Template" maxOccurs="unbounded">
                                <xs:complexType mixed="true">
                                    <xs:sequence>
                                        <xs:element name="Field" minOccurs="0" maxOccurs="unbounded">
                                            <xs:complexType>
                                                <xs:simpleContent>
                                                    <xs:extension base="xs:string">
                                                        <xs:attribute name="Name" use="required" type="xs:string"/>
                                                    </xs:extension>
                                                </xs:simpleContent>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                    <xs:attribute name="Name" use="required" type="xs:string"/>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute name="Title" use="required" type="xs:string"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Is this XSD correct and how can I map the data?

I've got this so far:

Mapping CSV to XML

Result:

<Pages>
    <Page Title="PageA">
        <Template Name="PageTemplate">
            <Field Name="ProjectA"/>
        </Template>
    </Page>
    <Page Title="PageB">
        <Template>
            <Field Name="ProjectA"/>
        </Template>
    </Page>
    <Page Title="PageC">
        <Template Name="PageTemplate">
            <Field Name="ProjectB"/>
        </Template>
    </Page>
</Pages>

Well, it's a start, but I can't figure out how to get the desired XML.

Can someone please help me a bit?


Solution

  • See http://www.altova.com/forum/default.aspx?g=posts&t=1100001095 for a nice solution I got at the Altova forum.