Model XML parsing without specific order
This commit is contained in:
parent
88f0c6a7b9
commit
b8787a9f5f
|
@ -6,11 +6,11 @@
|
|||
|
||||
<!-- Model identity informations -->
|
||||
<identity>
|
||||
<name>Modèle de test</name>
|
||||
<author>Adrien Bourmault</author>
|
||||
<author_id>1</author_id>
|
||||
<date>2021-08-21-21h34m44s</date> <!-- TODO timestamp ? -->
|
||||
<version>1.0</version>
|
||||
<name>Modèle de test</name>
|
||||
|
||||
</identity>
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue