Skip to content

Commit

Permalink
add xml (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjaudiomv authored Mar 18, 2024
1 parent 9e71f75 commit 64a3085
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# BMLT Data Converter

- Converts BMLT data from JSON to CSV, XLSX KML, or YAML
- Converts BMLT data from JSON to CSV, XLSX, XML KML, or YAML
- Note that export of KML is only supported with GetSearchResults.
- Use your semantic interface to build query url. You can find your semantic url by visiting the
[tally](https://tally.bmlt.app/) and hitting Explore on your root server.
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"fetch-jsonp": "^1.3.0",
"gh-pages": "^6.1.1",
"js-yaml": "^4.1.0",
"js2xmlparser": "^5.0.0",
"prettier": "^3.1.1",
"prettier-plugin-svelte": "^3.1.2",
"sass": "^1.71.0",
Expand Down
10 changes: 8 additions & 2 deletions src/lib/DataConverter.svelte
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<script lang="ts">
import { writable } from 'svelte/store';
import { fetchData, exportCSV, exportXLSX, exportKML, exportYAML } from './DataUtils';
import { fetchData, exportCSV, exportXLSX, exportXML, exportKML, exportYAML } from './DataUtils';
const processing = writable<boolean>(false);
const errorMessage = writable<string>('');
let query: string = '';
let csvDownloadUrl: string = '';
let xlsxDownloadUrl: string = '';
let xmlDownloadUrl: string = '';
let kmlDownloadUrl: string = '';
let yamlDownloadUrl: string = '';
Expand All @@ -15,6 +16,7 @@
errorMessage.set('');
csvDownloadUrl = '';
xlsxDownloadUrl = '';
xmlDownloadUrl = '';
kmlDownloadUrl = '';
yamlDownloadUrl = '';
Expand All @@ -23,6 +25,7 @@
const data = await fetchData(query);
csvDownloadUrl = exportCSV(data);
xlsxDownloadUrl = exportXLSX(data);
xmlDownloadUrl = exportXML(data);
yamlDownloadUrl = exportYAML(data);
kmlDownloadUrl = query.includes('GetSearchResults') ? exportKML(data) : '';
} catch (error) {
Expand Down Expand Up @@ -52,13 +55,16 @@
{#if xlsxDownloadUrl}
<a href={xlsxDownloadUrl} class="download-links" download="BMLT_data.xlsx">Download XLSX</a><br />
{/if}
{#if xmlDownloadUrl}
<a href={xmlDownloadUrl} class="download-links" download="BMLT_data.xml">Download XML</a><br />
{/if}
{#if kmlDownloadUrl}
<a href={kmlDownloadUrl} class="download-links" download="BMLT_data.kml">Download KML</a><br />
{/if}
{#if yamlDownloadUrl}
<a href={yamlDownloadUrl} class="download-links" download="BMLT_data.yaml">Download YAML</a>
{/if}
<div id="description">Converts BMLT data from JSON to CSV, XLSX, KML or YAML</div>
<div id="description">Converts BMLT data from JSON to CSV, XLSX, XML, KML or YAML</div>
</div>
<div id="footer">
<a href="https://github.com/bmlt-enabled/bmlt-data-converter/issues" class="footer-link" target="_blank">Issues?</a>
Expand Down
8 changes: 8 additions & 0 deletions src/lib/DataUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fetchJsonp from 'fetch-jsonp';
import * as XLSX from 'xlsx';
import * as js2xmlparser from 'js2xmlparser';
import * as yaml from 'js-yaml';

interface Meeting {
Expand Down Expand Up @@ -57,6 +58,13 @@ export function exportYAML(data: any[]): string {
return URL.createObjectURL(blob);
}

export function exportXML(data: any[]): string {
const processedData = processExportData(data);
const xmlResult = js2xmlparser.parse('root', processedData);
const blob = new Blob([xmlResult], { type: 'text/xml' });
return URL.createObjectURL(blob);
}

export function exportXLSX(data: any[]): string {
const processedData = processExportData(data);
const wb = XLSX.utils.book_new();
Expand Down

0 comments on commit 64a3085

Please sign in to comment.