process newline things
This commit is contained in:
parent
f820c978fc
commit
54806705c5
3 changed files with 105 additions and 18 deletions
14
example.c
14
example.c
|
|
@ -1,18 +1,24 @@
|
|||
#include <xmllib.h>
|
||||
|
||||
#define INDENT 2
|
||||
|
||||
void recursive(xmllib_node_t* node, int indent) {
|
||||
int i;
|
||||
xmllib_node_t* n;
|
||||
for(i = 0; i < indent; i++) printf(" ");
|
||||
if(node->name != NULL && node->type == XMLLIB_NODE_NODE) {
|
||||
printf("<%s>\n", node->name);
|
||||
if(node->text != NULL) {
|
||||
for(i = 0; i < indent + INDENT; i++) printf(" ");
|
||||
printf("%s\n", node->text);
|
||||
}
|
||||
} else if(node->text != NULL && node->type == XMLLIB_NODE_COMMENT) {
|
||||
printf("<!--%s-->\n", node->text);
|
||||
}
|
||||
|
||||
n = node->first_child;
|
||||
while(n != NULL) {
|
||||
recursive(n, indent + 2);
|
||||
recursive(n, indent + INDENT);
|
||||
n = n->next;
|
||||
}
|
||||
|
||||
|
|
@ -30,9 +36,11 @@ int main(int argc, char** argv) {
|
|||
if(h != NULL) {
|
||||
printf("%s:\n", argv[i]);
|
||||
if(xmllib_parse(h)) {
|
||||
if(h->root != NULL) recursive(h->root, 2);
|
||||
if(h->root != NULL) recursive(h->root, INDENT);
|
||||
} else {
|
||||
printf(" Parse error\n");
|
||||
int j;
|
||||
for(j = 0; j < INDENT; j++) printf(" ");
|
||||
printf("Parse error\n");
|
||||
}
|
||||
xmllib_close(h);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue