Skip to main content
Solved

how to extract attributes definition and export it to excel or word

  • October 21, 2017
  • 4 replies
  • 338 views

boubcher
Contributor
Forum|alt.badge.img+11

how could we extract the attribute definition of all reader in the workspace , the idea is to build a technical document in word or excel, to define all the attributes

Best answer by takashi

Hi @boubcher, you can read the schema definition of any dataset with the Schema (Any Format) reader. Each schema feature output from the reader will have a list attribute called "attribute{}" which contains the definition of all user attributes of a feature class. The list is a structured one consisting of these three members.

  • attribute{}.name: Attribute name
  • attribute{}.fme_data_type: FME generic data type
  • attribute{}.native_data_type: Native data type of the attribute (format specific)

You can use the ListExploder to decompose the list into individual elements, and then write them into an Excel spreadsheet.

View original
Did this help you find an answer to your question?

4 replies

takashi
Influencer
  • Best Answer
  • October 21, 2017

Hi @boubcher, you can read the schema definition of any dataset with the Schema (Any Format) reader. Each schema feature output from the reader will have a list attribute called "attribute{}" which contains the definition of all user attributes of a feature class. The list is a structured one consisting of these three members.

  • attribute{}.name: Attribute name
  • attribute{}.fme_data_type: FME generic data type
  • attribute{}.native_data_type: Native data type of the attribute (format specific)

You can use the ListExploder to decompose the list into individual elements, and then write them into an Excel spreadsheet.


boubcher
Contributor
Forum|alt.badge.img+11
  • Author
  • Contributor
  • October 22, 2017
takashi wrote:

Hi @boubcher, you can read the schema definition of any dataset with the Schema (Any Format) reader. Each schema feature output from the reader will have a list attribute called "attribute{}" which contains the definition of all user attributes of a feature class. The list is a structured one consisting of these three members.

  • attribute{}.name: Attribute name
  • attribute{}.fme_data_type: FME generic data type
  • attribute{}.native_data_type: Native data type of the attribute (format specific)

You can use the ListExploder to decompose the list into individual elements, and then write them into an Excel spreadsheet.

Thanks Takashi

 


paalped
Contributor
Forum|alt.badge.img+5
  • Contributor
  • August 6, 2018

I came across the problem, but in my case I did not have access to the source_datasets, so I could not run the workspace, but I wanted to extract every user attribute. So what i did was to make a script to extract the data from the .fmw file and it goes as follows:

import xml.etree.cElementTree as ET
workspace = r'C:\Enter\Your\Workspace\Here.fmw'

with open(workspace) as f:
    lines = []
    line = f.readline()
    while True:
        if not line:
            break
        if line.startswith('#!'):
            lines.append(line)
        elif line.startswith('#'):
            pass
        else:
            break
        line = f.readline()
    with open('fmw2xml.xml','w'as fw:
        fw.write(''.join(lines).replace('#! ',''))

xml =  ET.parse('fmw2xml.xml')
for feature_type in xml.iter('FEATURE_TYPE'):
    with open(f'{feature_type.attrib["NODE_NAME"]}.csv''w+'as csv:
        _header = False
        for child in feature_type.iter('FEAT_ATTRIBUTE'):
            if not _header:
                csv.write(';'.join(child.attrib.keys())+'\n')
                _header = True
            csv.write(';'.join(child.attrib.values())+'\n')

Now what this does it creates a csv file for every reader in your workspace, and inside each csv is the user attributes. code tested in py 3.6 , for 2.7 f strings must be converted to supported string format.


Forum|alt.badge.img
  • July 6, 2020
takashi wrote:

Hi @boubcher, you can read the schema definition of any dataset with the Schema (Any Format) reader. Each schema feature output from the reader will have a list attribute called "attribute{}" which contains the definition of all user attributes of a feature class. The list is a structured one consisting of these three members.

  • attribute{}.name: Attribute name
  • attribute{}.fme_data_type: FME generic data type
  • attribute{}.native_data_type: Native data type of the attribute (format specific)

You can use the ListExploder to decompose the list into individual elements, and then write them into an Excel spreadsheet.

What about on a DB connection?


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings