Exemplu practic de XML

O sa vorbim despre XML pt ca este foarte important in lucrul cu date !

Foarte multa lume spune ca nu poate zice exact ce este xml-ul ,dar poate spune ce nu este…
Ei bine, XML ESTE o buna solutie de a stoca date intr-o structura usor de folosit.
XML se constituie intr-o strucutra – TREE(structura arborescenta)
O sa va dau un exemplu de structura arborescenta care descrie orarul saptamanal al unui student:

<?xml version=”1.0″ ?>

<?xml-stylesheet type=”text/xsl” href=”orar.xsl” ?>

<ORAR>

<ZI denumire=”Luni”>

<RAND>

<INTERVAL begin=”8″ end=”10″ />

<MATERIE>Ingineria programarii </MATERIE>

<TIP>Laborator</TIP>

<PROFESOR>Mariana Mocanu </PROFESOR>

<SALA>EF001</SALA>

</RAND>

<RAND>

<INTERVAL begin=”10″ end=”12″ />

<MATERIE>Ingineria programarii </MATERIE>

<TIP>Curs</TIP>

<PROFESOR>Mariana Mocanu </PROFESOR>

<SALA>EF001</SALA>

</RAND>

<RAND>

<INTERVAL begin=”14″ end=”16″ />

<MATERIE>L.E.P. </MATERIE>

<TIP>Curs</TIP>

<PROFESOR>Stefan-Trausan Matu</PROFESOR>

<SALA>EF001</SALA>

</RAND>

</ZI>

<ZI denumire=”Marti”>

<RAND>

<INTERVAL begin=”8″ end=”10″ />

<MATERIE>Sisteme de operare </MATERIE>

<TIP>Curs</TIP>

<PROFESOR>Liviu Ristovschi </PROFESOR>

<SALA>EF001</SALA>

</RAND>

<RAND>

<INTERVAL begin=”10″ end=”12″ />

<MATERIE>Sisteme de operare </MATERIE>

<TIP>Laborator</TIP>

<PROFESOR>Liviu Ristovschi </PROFESOR>

<SALA>EF001</SALA>

</RAND>

<RAND>

<INTERVAL begin=”14″ end=”16″ />

<MATERIE>L.E.P. </MATERIE>

<TIP>Curs</TIP>

<PROFESOR>Stefan-Trausan Matu</PROFESOR>

<SALA>EF001</SALA>

</RAND>

</ZI>

</ORAR>

XSLT – Descrierea arborescenta a unui orar

In continuare descriem si modul in care dorim sa fie afisata informatia arborescenta din articolul precedent care descrie un orar studentesc. Pentru aceasta vom folosi limbajul XSLT :

<xsl:stylesheet version=”1.0″

xmlns: xsl=”http://www.w3.org/1999/XSL/Transform”&gt;

<xsl: template match=”/”>

<html>

<body>

<xsl:for-each select=”ORAR/ZI/RAND”>

<xsl:choose>

<xsl: when test=”INTERVAL[@begin=12]” >

<font color=”red”>

<xsl: value-of select=”MATERIE”/>

</font>

</xsl: when>

 

<xsl: otherwise>

<font color=”red”>

<xsl: value-of select=”MATERIE”/>

</font>

</xsl: otherwise>

 

</xsl: choose>

</xsl: for-each>

</body>

</html>

</xsl: template>

</xsl: stylesheet>