Formatarea arborescenta a datelor.

Uneori este nevoie ca date liniare extrase din baza de date sa fie formatate arborescent.

Fiecare definitie  contine unul sau mai multe noduri /level, cate unul pentru fiecare nivel al formatarii, in ordinea nivelului de formatare. Fiecare nod level are atributul node_name care defineste numele nodului xml creat pentru acel nivel, atributul repeat care are o valoare de tip boolean si specifica daca nivelul respectiv este repetabil. Daca nivelul este repetabil, exista un al treilea atribut: trigger. Acest atribut specifica valoarea carei coloane sa determine crearea unui nou nod la acel nivel.

In interiorul fiecarui nod /level pot exista noduri de tip attr sau node. Acestea specifica daca datele din coloane trebuie puse in rezultat ca valoare de nod xml sau ca valoare de atribut. Ambele noduri au atributele name care specifica numele nodului sau atributului in care trebuie puse valorile, si atributul data care specifica din ce coloana se iau datele. Daca nodul de la un anumit nivel nu are noduri in care se pun valorile, acel nivel de nod poate avea valoarea scrisa direct in el. Acest lucru se obtine prin utilizarea nodului value care are atributul data (care specifica din ce coloana se iau datele).

Un astfel de exemplu este o structura de tip marc, structura care pe primul nivel are record-ul, pe al doilea nivel campurile si pe al treilea subcampurile.

Exemplu de functionare:

Mesaj (cerere) client:

<?xml version="1.0" encoding="UTF-8"?>
<x>
  <m t="MultiLevelDetail">
    <p>AddAdvanced</p>
    <o>btnAdd</o>
    <pre>usr</pre>
    <clear>true</clear>
    <fld/>
    <id>133</id>
    <lang>rou</lang>
    <opt>[excludeAutomaticFields]</opt>
    <opid>
      <l>
        <function>AddAdvanced.Busy.setbusy(false)</function>
        <function>AddAdvanced.btnAdd.setFocus()</function>
      </l>
    </opid>
  </m>
</x>

Definitie actiune in limbaj:

<action>
 <actionType>MySQLMultilevel</actionType>
 <MySQLreply>
   <procedure>
     <call>marc_select_details('$/pre$', '$/id$', '$/fld$', '', '$/opt$');</call>
     <fieldNames>id_object,cat_object,id_field,tag_field,id_subfield,name_subfield,value_subfield,lang_field,aut_subfield,ordf,ords</fieldNames>
   </procedure>
   <result>
     <parentNode>
       <name>x</name>
       <attr>t='SetMLForm' p='$/p$' o='$/o$' clear='$/clear$'</attr>
     </parentNode>
     <row>Unimarc</row>
   </result>
 </MySQLreply>
</action>

Definitie de formatare:

<Unimarc>
  <level node_name='object' repeat='true' trigger='rid' >
    <node name='rlb' data='rid' />
    <node name='cat' data='ctg' />
  </level>
  <level node_name='fld' repeat='true' trigger='fid' >
    <attr name='id' data='fid' />
    <attr name='nam' data='nam' />
    <attr name='lang' data='lng' />
    <attr name='ord' data='ordf' />
  </level>
  <level node_name='sub' repeat='true' trigger='sid' >
    <attr name='id' data='sid' />
    <attr name='nam' data='sub' />
    <attr name='ord' data='ords' />
  </level>
  <level node_name='val' repeat='false'>
    <attr name='aut' data='aid' /> 
    <value data='val' /> 
  </level>
</Unimarc>

Selectie din baza de date:

call marc_select_details('usr', '25133', '', '', '[excludeAutomaticFields]');

multilevelselect

Raspuns formatat:

<x t='SetMLForm' p='AddAdvanced' o='btnAdd' clear='true'>
  <object >
    <cat>bibliotecar</cat>
    <rlb>133</rlb>
    <fld ord='0' id='113' nam='200' lang='rou' >
      <sub ord='1' id='8' nam='a' >
        <val aut='0' >bib</val>
      </sub>
      <sub ord='1' id='9' nam='b' >
        <val aut='0' >1985-03-20</val>
      </sub>
      <sub ord='2' id='10' nam='g' >
        <val aut='3807' >M</val>
      </sub>
      <sub ord='3' id='11' nam='e' >
         <val aut='4022' >0</val>
      </sub>
    </fld>
    <fld ord='0' id='125' nam='299' lang='rou' >
      <sub ord='0' id='1' nam='a' >
        <val aut='0' >bib</val>
      </sub>
    </fld>
    <fld ord='2' id='5738' nam='215' lang='rou' >
      <sub ord='1' id='23' nam='1' >
        <val aut='0' >bibliotecar@mail.ro</val>
      </sub>
      <sub ord='1' id='24' nam='a' >
        <val aut='0' >mail.ro</val>
      </sub>
      <sub ord='2' id='25' nam='b' >
        <val aut='0' >993</val>
      </sub>
      <sub ord='3' id='26' nam='c' >
        <val aut='0' >bibliotecar@mail.ro</val>
      </sub>
      <sub ord='4' id='27' nam='d' >
        <val aut='0' >ocvdff(*&jkd7</val>
      </sub>
      <sub ord='5' id='28' nam='e' >
        <val aut='0' >11</val>
      </sub>
      <sub ord='6' id='29' nam='h' >
        <val aut='0' >true</val>
      </sub>
      <sub ord='7' id='30' nam='o' >
        <val aut='0' >mail.ro</val>
      </sub>
      <sub ord='8' id='31' nam='p' >
        <val aut='0' >587</val>
      </sub>
      <sub ord='9' id='32' nam='q' >
        <val aut='0' >bibliotecar@mail.ro</val>
      </sub>
      <sub ord='10' id='33' nam='r' >
        <val aut='0' >dsc8s7sd&*NBKj6y</val>
      </sub>
      <sub ord='11' id='34' nam='t' >
        <val aut='0' >true</val>
      </sub>
      <sub ord='12' id='35' nam='s' >
        <val aut='0' >11</val>
      </sub>
      <sub ord='13' id='36' nam='v' >
        <val aut='0' >true</val>
      </sub>
    </fld>
    <fld ord='3' id='593' nam='500' lang='rou' >
      <sub ord='0' id='2' nam='i' >
        <val aut='5635' >1.1.</val>
      </sub>
    </fld>
    <fld ord='4' id='177' nam='412' lang='rou' >
      <sub ord='0' id='1' nam='t' >
        <val aut='5623' >2</val>
      </sub>
      <sub ord='1' id='2' nam='t' >
        <val aut='5622' >1</val>
      </sub>
      <sub ord='2' id='3' nam='t' >
        <val aut='5621' >0</val>
      </sub>
    </fld>
    <fld ord='5' id='130' nam='444' lang='rou' >
      <sub ord='0' id='5' nam='p' >
        <val aut='91' >rmf</val>
      </sub>
      <sub ord='1' id='6' nam='g' >
        <val aut='0' >7</val>
      </sub>
      <sub ord='2' id='7' nam='i' >
        <val aut='0' >5</val>
      </sub>
      <sub ord='3' id='8' nam='o' >
        <val aut='0' >1</val>
      </sub>
    </fld>
  </object>
</x>
Sidebar