Dilib, module SxmlNode, constructeur SxmlFromString

De Wicri Outils
LogoDilib.gif
Panneau travaux.png
Bibliothèque Dilib (ressources numériques)
Module SxmlNode

Le constructeur SxmlFromString crée un objet de type SxmlNode à partir d'une chaîne de caractères. Il est plus particulièrement adapté aux documents créés dans un environnement Sxml.

Pour mieux traiter les documents venant du monde XML strict, à partir de la version V0.5.57 un ensemble de constructeurs complémentaires ont été créés. Le plus généralement pertinent est SxmlElementFromString.

 

Constructeur SxmlFromString

Synopsis
#include "SxmlNode.h"
SxmlNode *SxmlFromString(char *str);
Paramètre

Le paramètre str pointe sur la chaîne à compiler.

Exemple
char * myString;
SxmlNode *myNodeHello;
myString="<hello>World</hello><ciao>Empty</ciao>";
myNodeHello=SxmlFromString(myString);
SxmlPrint(myNodeHello);   /*  prints only : <hello>World</hello>  */

Constructeur SxmlFromStringNext

Synopsis
#include "SxmlNode.h"
SxmlNode *SxmlFromStringNext();
Usage

Après un premier appel de SxmlFromString ce constructeur permet de compiler l'objet XML suivant dans la chaîne.

Exemple
char * myString;
SxmlNode *myNodeHello;
SxmlNode *myNodeCiao;
myString="<hello>World</hello><ciao>Empty</ciao>";
myNodeHello=SxmlFromString(myString);
SxmlPrint(myNodeHello);   /*  prints only : <hello>World</hello>  */
myNodeCiao=SxmlFromString(myString);
SxmlPrint(myNodeCiao);   /*  prints now : <ciao>Empty</ciao>  */

Constructeur SxmlFromStringInit

Ce constructeur permet d'initialiser une boucle d'appel à SxmlFromStringNext (sans passer par SxmlFromString).

Synopsis
#include "SxmlNode.h"
SxmlNode *SxmlFromStringInit(char *str);
Exemple
char * myString;
SxmlNode *myNode;
myString="<hello>World</hello><ciao>Empty</ciao>";
SxmlFromStringInit(myString);
while ((myNode=SxmlFromStringNext()))
  {
      SxmlPrint(myNode);
      putchar('\n');
  }

Constructeur SxmlElementFromString

Synopsis
#include "SxmlNode.h"
SxmlNode *SxmlElementFromString(char *str);
Paramètre

Le paramètre str pointe sur la chaîne à compiler.

Exemple
char * myString;
SxmlNode *myNodeHello;
myString="<?xml version="1.0" ?><hello>World</hello>";
myNodeHello=SxmlElementFromString(myString);
SxmlPrint(myNodeHello);   /*  prints only : <hello>World</hello>  */

Fonction réciproque SxmlToString</code

#include "SxmlNode.h"
char *SxmlToString(SxmlNode *x1);

Cette fonction génère une chaîne de caractère correspondant à l'arbre donné en paramètre.

Attention : Cette fonction retourne un pointeur sur une chaîne volatile. un clonage par strdup est nécessaire en cas d'appels multiples à la fonction