Dilib, module SxmlNode, type SxmlAttribute
De Wicri Outils
Révision datée du 7 juillet 2020 à 14:28 par imported>Jacques Ducloy (→Fonction SxmlGetAttribute)
Module SxmlNode |
Ce module introduit les fonctions relatives aux attributs des éléments Sxml.
Liste des modules Dilib
Module SxmlNode
|
Fonctions de base
Fonction SxmlSetAttribute
Cette fonction ajoute ou modifie un attribut.
- Synopsis
SxmlNode *SxmlSetAttribute(SxmlNode *elem, char *attributeName, char *attributeValue);
- paramètres
- elem : le nœud sur lequel s'applique la fonction.
- attributeName : le nom de l'attribut à modifier (ou créer) ;
- attributeValue : la valeur de l'attribut à modifier (ou créer) ;
- exemple
SxmlNode *hello;
hello=SxmlElementCreate("hello"); /* hello : <hello></hello> */
SxmlSetAttribute (hello, "who", "World"); /* hello : <hello who="World"></hello> */
Fonction SxmlGetAttributeNode
- Synopsis
SxmlNode *SxmlGetAttributeNode(SxmlNode *elem, char *attributeName);
Cette fonction retourne un pointeur vers l'attribut dont le nom est donné en paramètre (NULL sinon).
Pour accéder directement à la valeur voir SxmlGetAttribute.
Fonction SxmlGetAttribute
- Synopsis
char *SxmlGetAttribute(SxmlNode *elem, char *attributeName);
- Exemple
SxmlNode *n1;
n1=SxmlFromText("<statistics pages=\"1621\" jobs=\"0\"/>");
printf ("%s\n", SxmlGetAttribute(n1, "pages")); /* imprime 1621 */
printf ("%d\n", atoi(SxmlGetAttribute(n1, "pages"))+10); /* imprime 172 */
Fonction SxmlHasAttribute
- Synopsis
SxmlNode *SxmlHasAttribute(SxmlNode *elem, char *attributeName, char *attributeValue);
- Exemple
SxmlNode *idnoNode;
char *rbid;
...
if (SxmlHasAttribute(idnoNode, "type", "RBID")) rbid=SxmlLeafText(idnoNode);
...
Fonctions dérivées
Fonction SxmlSetIntAttribute
- Synopsis
SxmlNode *SxmlSetIntAttribute(SxmlNode *node, char *key, int value);
Cette fonction facilite l'écriture de la création d'un attribut à valeur numérique. Cet attribut est rangé après une conversion en chaîne.
Fonction SxmlGetFirstChildTagAtt
- Synopsis
SxmlNode *SxmlGetFirstChildTagAtt(SxmlNode *parentNode,
char *nameChild,
char *attributeName, char *attributeValue);
- Définition
Cette fonction recherche le premier fils de parentNode qui possède :
- le nom nameChild donné en paramètre,
- l'attribut attributeName avec sa valeur attributeValue.
- Exemple
titleFrench=SxmlGetFirstChildTagAtt(metadataNode, "title", "xml:lang", "fr");