Created
February 24, 2016 16:33
-
-
Save kfeoktistoff/5b3aa19f1aa1feb0607d to your computer and use it in GitHub Desktop.
Parsing SAP BO (blx) file, saving folders, dimensions and measures in csv file. To get bxl file, add .zip to the end of business layer file and extract blx file inside the archive. This extraction path should be used as an inputFile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
inputFile=open('C:/tmp/input.blx', 'r') | |
outputFile=open('C:/tmp/output.csv', 'w+') | |
separator = ',' | |
def isDir(elem): | |
return elem.attrib.get('xsi:type') == 'business:Folder' | |
def isDimension(elem): | |
return elem.attrib.get('xsi:type') == 'business:Dimension' | |
def isMeasure(elem): | |
return elem.attrib.get('xsi:type') == 'business:Measure' | |
def isDimensionOrMeasure(elem): | |
return isDimension(elem) or isMeasure(elem) | |
def printFolderCsv(directory, path): | |
currentPath = list(path) | |
currentPath.append(directory.attrib.get('businessName')) | |
writeOutput('F', currentPath) | |
for child in directory: | |
if isDir(child): | |
print(child.attrib.get('businessName')) | |
childPath = list(currentPath) | |
printFolderCsv(child, childPath) | |
elif isDimensionOrMeasure(child): | |
childPath = list(currentPath) | |
childPath.append(child.attrib.get('businessName')) | |
writeDimOrMes(child, childPath) | |
return | |
def writeOutput(type, path): | |
str = '"' + type + '"' | |
for i in reversed(path): | |
str += separator + '"' + i + '"' | |
outputFile.write(str + '\n') | |
def writeDimOrMes(child, path): | |
if (isDimension(child)): | |
writeOutput('D', path) | |
else: | |
writeOutput('M', path) | |
root = ET.parse(inputFile) | |
result = '' | |
for elem in root.findall('./*/businessItems'): | |
if isDir(elem): | |
printFolderCsv(elem, []) | |
elif isDimensionOrMeasure(elem): | |
writeDimOrMes(elem, []) | |
Hello,
You're right, the parser works with older version of SAP BO. Since 4.1 the format is binary and the script doesn't work any more
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your .blx file inside the blx zipped file in xml format? Mine looks funky when I open it in Notepad++. I've tried various encodings with no luck.

What version of IDT were you using? I'm using 4.1.

I ran you code for my file and it gave a "xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0" error. Which makes sense since the file is not in xml format.