Posted to tcl by de at Wed Apr 26 19:07:32 GMT 2017view raw
- # This doesn't run. It's just an illustrating example
- package require tdom
- # Define the elements of your XML vocabulary as nodeCmds
- foreach element {
- CLASSIFICATION_SYSTEM
- CLASSIFICATION_SYSTEM_NAME
- CLASSIFICATION_SYSTEM_FULLNAME
- CLASSIFICATION_SYSTEM_VERSION
- CLASSIFICATION_SYSTEM_DESCR
- CLASSIFICATION_SYSTEM_LEVELS
- ...
- } {
- dom createNodeCmd elementNode $element
- }
- # A nodeCmd to generate text nodes
- dom createNodeCmd textNode t
- # Here an example to build an XML tree from (nested) sqlite db
- # queries:
- set synonymQuery {
- SELECT pcSchlagworte.Schlagwortbezeichnung
- FROM pcKlassenSchlagworte_rel, pcSchlagworte
- WHERE Klasse_ID = $Klassen_ID
- AND pcSchlagworte.Schlagwort_ID
- = pcKlassenSchlagworte_rel.Schlagwort_ID
- }
- set featureQuery {
- SELECT pcMerkmale.Merkmal_ID, pcMerkmale.Datentyp, Einheit_ID,
- Sortiert_Nr, Mussmerkmal, KlasseMerkmal_Nr
- FROM pcKlassenMerkmale_rel, pcMerkmale
- WHERE Klasse_ID = $Klassen_ID
- AND pcMerkmale.Merkmal_ID = pcKlassenMerkmale_rel.Merkmal_ID
- }
- set valueQuery {
- SELECT Wert_ID FROM pcKlassenMerkmaleWerte_rel
- WHERE KlasseMerkmal_Nr = $KlasseMerkmal_Nr
- }
- db eval {SELECT * FROM pcKlassen} {} {
- $classification_groups appendFromScript {
- CLASSIFICATION_GROUP level $Hierarchieebene {
- CLASSIFICATION_GROUP_ID {t $Klassen_ID}
- CLASSIFICATION_GROUP_NAME {t $Klassenbezeichnung}
- set synonyms [db eval $synonymQuery]
- if {[llength $synonyms] > 0} {
- CLASSIFICATION_GROUP_SYNONYMS {
- foreach synonym $synonyms {
- SYNONYM {t $synonym}
- }
- }
- }
- set features [db eval $featureQuery]
- if {[llength $features] > 0} {
- CLASSIFICATION_GROUP_FEATURE_TEMPLATES {
- foreach {Merkmal_ID Datentyp Einheit_ID Sortier_NR Mussmerkmal KlasseMerkmal_Nr} $features {
- CLASSIFICATION_GROUP_FEATURE_TEMPLATE {
- FT_IDREF {t $Merkmal_ID}
- switch $Mussmerkmal {
- "TRUE" {
- FT_MANDATORY {t "true"}
- }
- "FALSE" {
- FT_MANDATORY {t "false"}
- }
- default {
- puts stderr "FEATURE mit unbekanntem Mussmerkmal \
- '$Mussmerkmal'"
- FT_MANDATORY {}
- }
- }
- set valueIDs [db eval $valueQuery]
- FT_DATATYPE {
- switch $Datentyp {
- "numerisch" {
- t "N"
- }
- "alphanumerisch" {
- if {[llength $valueIDs] > 0} {
- t "A"
- } else {
- t "X"
- }
- }
- "logisch" {
- t "L"
- }
- default {
- puts stderr "Unbekannter FT_DATATYPE '$Datentyp'"
- t $Datentyp
- }
- }
- }
- if {$Einheit_ID ne ""} {
- FT_UNIT {
- t $Einheit_ID
- }
- }
- FT_ORDER {t $Sortier_NR}
- if {[llength $valueIDs] > 0} {
- FT_ALLOWED_VALUES {
- foreach valueID $valueIDs {
- ALLOWED_VALUE_IDREF {t $valueID}
- }
- }
- }
- }
- }
- }
- }
- if {$Hierarchieebene > 1} {
- CLASSIFICATION_GROUP_PARENT_ID {t $Parent_ID}
- }
- }
- }
- }