[xml] node->children or node->next, pointer to a "text" node..



I'm writing from Turkey and my English very poor :( Excuse Me...

I tried libxml2. Our connections very slow. I download libxml2-2.4.16-1.rpm's (binary, both devel and lib) 
from rpmfind. I read all doc pages and xmlsoft.org pages this day morning.. I Tried your "Real Example". But 
i cannot be use this library :(

A xml file: called conf. file. No XSLT or namespace. First Paragraph..:

<?xml version="1.0" encoding="ISO8859-9"?>
<PackConfig>
        <main>
                <packname>
                     Deneme Paketi
                </packname>
                <filename>
                     TestPackage.rpm
                </filename>
                <packversion>
                        <major>1</major>
                        <minor>0</minor>
                        <plev>0</plev>
                </packversion>
        </main>
        <provides>
                <library param="1 2">
                     <desc locale="tr">
                             MPEG Encoder Librarysi.
                     </desc>
                     <dbcompability>
                          <from>1.0.0</from>
                          <to>1.5.2</to>
                          <dllalias>libsdl.so</dllalias>
                          <dllversion>1/2/3</dllversion>
                     </dbcompability>
                </library>
        </provides>
</PackConfig>

And I parse this file with xmlParseFile.. I'm writing simple code for this test:

#include <stdio.h>
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
//#include <libxml2/libxml/tree.h>
#include <regex.h>
#include <errno.h>
#include <libxml/parser.h>

int main() {
    xmlDocPtr   conf; 
    xmlNodePtr  node;
    xmlNodePtr  catMain, catProv;
 
    xmlInitParser();
    
    conf = xmlParseFile("../data/sample.xml");
    node = xmlDocGetRootElement(conf);
    node = node->xmlChildrenNode;
    
    while ( node != NULL ) {
      switch (1) {
        default:      
          if (strcasecmp(node->name, "provides") == 0) {
             catProv = node;
             getAndView(node, conf);
             break;
          }       
          if (strcasecmp(node->name, "main") == 0) {
             catMain = node;
             break;
          }       
          printf("NODE: %s \n", node->name);
       }
       node = node->next;
    }
}

void getAndView(xmlNodePtr cur, xmlDocPtr doc) 
{
   
    printf("Node entry: %s ", cur->name);
    printf(" Data -> %s \n", xmlNodeListGetRawString(doc, cur, 1));
    if (cur->xmlChildrenNode != NULL) {
       getAndView(cur->xmlChildrenNode, doc);
    } else {
       if (cur->next != NULL) {
           getAndView(cur->next, doc);
       } else {
           return;
       }
    
    }
}

This program output is ( on not understanding lines, marked at ??? ) :

NODE: text  ???
NODE: text ???
Node entry: provides  Data ->  
Node entry: text  Data ->  ????
Node entry: library  Data -> 
Node entry: text  Data ->  ????
Node entry: desc  Data -> 
Node entry: text  Data -> MPEG Encoder Librarysi..
 
I'm confused. I search mail archives. FAQ's etc.. But not found (or not see) a information.. 

1. "text" nodes ?  What ?
2. Do not reached child nodes. What ?

Excuse me.. Yes, I'm a newbie for libxml and xml... 

Thanks..

_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]