From b8787a9f5f8280e12e46c19c330b351af2400ce1 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Tue, 24 Aug 2021 12:40:51 +0200 Subject: [PATCH] Model XML parsing without specific order --- debian/var/models/example.xml | 2 +- include/xml.h | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/debian/var/models/example.xml b/debian/var/models/example.xml index 9d66ff7..04108b0 100644 --- a/debian/var/models/example.xml +++ b/debian/var/models/example.xml @@ -6,11 +6,11 @@ + Modèle de test Adrien Bourmault 1 2021-08-21-21h34m44s 1.0 - Modèle de test diff --git a/include/xml.h b/include/xml.h index fd7a86d..337b5e8 100644 --- a/include/xml.h +++ b/include/xml.h @@ -68,6 +68,7 @@ static inline void resetDocumentRoot(void) static inline int parseTag(const char* tagName, char *destination, char destSize) { char *curString; + size_t cursor = 0; char res = 0; xmlNodePtr cur = currentDocumentRoot; @@ -87,7 +88,12 @@ static inline int parseTag(const char* tagName, char *destination, char destSize // Check there is text in that tag (and that is asked) if (destination && curString[0] != '\n') { - snprintf(destination, destSize, "%s\n", curString); + cursor = + snprintf( + destination + cursor * sizeof(char), + destSize, + "%s\n", + curString); res++; } free(curString); @@ -124,6 +130,7 @@ static inline xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot) static inline int parseTree(ModelField_t *curTree) { int currentOrSonCorrectlyParsed = 0; + int curValueLen; while (curTree) { if (findRoot( @@ -141,6 +148,19 @@ static inline int parseTree(ModelField_t *curTree) // There are values in that tag if (curTree->value[0]) if (!(curTree->value[0] == '\0')) { + curValueLen = strlen(curTree->value); + + // Delete \n chars + for(int i = 0; i < curValueLen; i++) { + if(curTree->value[i] == '\n') { + memmove(&curTree->value[i], + &curTree->value[i+1], + curValueLen - i); + curValueLen--; + i--; + } + } + strcat(curTree->value, "\n"); printLog("Field %s: %s", curTree->tag, curTree->value); } } else {