Question

dynamic XFMAP

  • 14 March 2018
  • 1 reply
  • 8 views

Hi,

I need advice. I would like to dynamicaly read XML fiel using XFMAP to create feature types and extract values. Here is my source XML:

<?xml version="1.0" encoding="UTF-8"?>
<b:DataTableList xmlns:b="http:\\wwww.b.com">
    <b:DavkaTable>
        <b:Name>dtCisTriedZnakKolaje</b:Name>
        <b:RowList>
            <b:Row>
                <b:ColumnList>
                    <b:Column>
                        <b:DataType>System.Int32</b:DataType>
                        <b:Name>C_TRIED_ZNAK_KOLAJE_NI_ID</b:Name>
                        <b:PrimaryKey>true</b:PrimaryKey>
                        <b:Value>1</b:Value>
                    </b:Column>
                    <b:Column>
                        <b:DataType>System.String</b:DataType>
                        <b:Name>KOD</b:Name>
                        <b:PrimaryKey>false</b:PrimaryKey>
                        <b:Value>01</b:Value>
                    </b:Column>                    
                </b:ColumnList>               
            </b:Row>
            <b:Row>
                <b:ColumnList>
                    <b:Column>
                        <b:DataType>System.Int32</b:DataType>
                        <b:Name>C_TRIED_ZNAK_KOLAJE_NI_ID</b:Name>
                        <b:PrimaryKey>true</b:PrimaryKey>
                        <b:Value>2</b:Value>
                    </b:Column>
                    <b:Column>
                        <b:DataType>System.String</b:DataType>
                        <b:Name>KOD</b:Name>
                        <b:PrimaryKey>false</b:PrimaryKey>
                        <b:Value>02</b:Value>
                    </b:Column>                   
                </b:ColumnList>              
            </b:Row>
        </b:RowList>
    </b:DavkaTable>
    <b:DavkaTable>
        <b:Name>dtCisDoprUrc</b:Name>
        <b:RowList>
            <b:Row>
                <b:ColumnList>
                    <b:Column>
                        <b:DataType>System.Int32</b:DataType>
                        <b:Name>C_DOPR_URCENIE_ID</b:Name>
                        <b:PrimaryKey>true</b:PrimaryKey>
                        <b:Value>1</b:Value>
                    </b:Column>
                    <b:Column>
                        <b:DataType>System.String</b:DataType>
                        <b:Name>KOD</b:Name>
                        <b:PrimaryKey>false</b:PrimaryKey>
                        <b:Value>Dopr</b:Value>
                    </b:Column>                    
                </b:ColumnList>                
            </b:Row>
            <b:Row>
                <b:ColumnList>
                    <b:Column>
                        <b:DataType>System.Int32</b:DataType>
                        <b:Name>C_DOPR_URCENIE_ID</b:Name>
                        <b:PrimaryKey>true</b:PrimaryKey>
                        <b:Value>2</b:Value>
                    </b:Column>
                    <b:Column>
                        <b:DataType>System.String</b:DataType>
                        <b:Name>KOD</b:Name>
                        <b:PrimaryKey>false</b:PrimaryKey>
                        <b:Value>Manip</b:Value>
                    </b:Column>                    
                </b:ColumnList>               
            </b:Row>
            <b:Row>
                <b:ColumnList>
                    <b:Column>
                        <b:DataType>System.Int32</b:DataType>
                        <b:Name>C_DOPR_URCENIE_ID</b:Name>
                        <b:PrimaryKey>true</b:PrimaryKey>
                        <b:Value>3</b:Value>
                    </b:Column>
                    <b:Column>
                        <b:DataType>System.String</b:DataType>
                        <b:Name>KOD</b:Name>
                        <b:PrimaryKey>false</b:PrimaryKey>
                        <b:Value>Osob</b:Value>
                    </b:Column>                   
                </b:ColumnList>                
            </b:Row>
        </b:RowList>
    </b:DavkaTable>
</b:DataTableList>


I would like to create feature type using davkaTable Name (/b:DataTableList/b:DavkaTable/b:Name) and each featuretype wil have own attributes defined in columnList section. I created following XFMAP file:

<xfMap>
    <feature-map multi-feature-construction="true">
        <note> construct an FME feature when we read the 'Feature' element. </note>
        <mapping match="b:DataTableList/b:DavkaTable">
            <feature-type>
                <extract expr="./b:Name"/>
            </feature-type>           
        </mapping>
    </feature-map>
      <feature-content-map>
          <mapping match="b:DataTableList/b:DavkaTable/b:RowList/b:Row/b:ColumnList/b:Column">
            <attributes>
                <attribute type="sequenced">
                    <name>
                        <extract expr="./b:Name"/>
                    </name>
                    <value>
                        <extract expr="./b:Value"/>
                    </value>
                </attribute>
            </attributes>
        </mapping>
  </feature-content-map> 
</xfMap>


Using this XFMAP I can create featuretypes structure, but I have problem to load values for each row. Only first row is taken into account instead 2 rows for featuretype dtCisTriedZnakKolaje and three rows for dtCisDoprUrc. Please, could you advice me, what is wrong ? Thank you very much.


1 reply

Userlevel 2
Badge +17

Hi @radochudy, I think you have to implement the cardinality attribute in <structure> element, in order to extract the Row elements as list attribute. See here to learn more: Structure Element

By the way, why not use the regular XML reader or the XMLFragmenter with flattening options?

Reply