Model XML parsing without specific order

This commit is contained in:
Adrien Bourmault 2021-08-24 12:40:51 +02:00
parent 88f0c6a7b9
commit b8787a9f5f
No known key found for this signature in database
GPG Key ID: 6EB408FE0ACEC664
2 changed files with 22 additions and 2 deletions

View File

@ -6,11 +6,11 @@
<!-- Model identity informations --> <!-- Model identity informations -->
<identity> <identity>
<name>Modèle de test</name>
<author>Adrien Bourmault</author> <author>Adrien Bourmault</author>
<author_id>1</author_id> <author_id>1</author_id>
<date>2021-08-21-21h34m44s</date> <!-- TODO timestamp ? --> <date>2021-08-21-21h34m44s</date> <!-- TODO timestamp ? -->
<version>1.0</version> <version>1.0</version>
<name>Modèle de test</name>
</identity> </identity>

View File

@ -68,6 +68,7 @@ static inline void resetDocumentRoot(void)
static inline int parseTag(const char* tagName, char *destination, char destSize) static inline int parseTag(const char* tagName, char *destination, char destSize)
{ {
char *curString; char *curString;
size_t cursor = 0;
char res = 0; char res = 0;
xmlNodePtr cur = currentDocumentRoot; 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) // Check there is text in that tag (and that is asked)
if (destination && curString[0] != '\n') { if (destination && curString[0] != '\n') {
snprintf(destination, destSize, "%s\n", curString); cursor =
snprintf(
destination + cursor * sizeof(char),
destSize,
"%s\n",
curString);
res++; res++;
} }
free(curString); free(curString);
@ -124,6 +130,7 @@ static inline xmlNodePtr findRoot(const char *tagName, xmlNodePtr curRoot)
static inline int parseTree(ModelField_t *curTree) static inline int parseTree(ModelField_t *curTree)
{ {
int currentOrSonCorrectlyParsed = 0; int currentOrSonCorrectlyParsed = 0;
int curValueLen;
while (curTree) { while (curTree) {
if (findRoot( if (findRoot(
@ -141,6 +148,19 @@ static inline int parseTree(ModelField_t *curTree)
// There are values in that tag // There are values in that tag
if (curTree->value[0]) if (curTree->value[0])
if (!(curTree->value[0] == '\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); printLog("Field %s: %s", curTree->tag, curTree->value);
} }
} else { } else {