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