RE: [xml] how to read the second node?



Ok, here is how you would do it (Sorta, this is not code but an example)..

doc=xmlDocGetRootElement(docname); // TIMETABLE
cur=cur->xmlChildrenNode;               // direct_train

Ok, now our pointer is @ direct train, assume we want to got to the next
node @ this level..

We would call cur=cur->next.            // This would yield passing1_train

If we wanted to got to direct_train's child instead of passing1_train:
cur=cur->xmlChildrenNode

Or for a final example..  Lets say we were @ <train number> on <direct
train> and we wanted to go back to direct train:

cur=cur->parent

Basically, look @ it like an outline where numbers below are levels of
depth, and letters are individual rows..

1       2       3       4
A
B
C
D

To go right in depth (i.e. A child) you would call xmlChildrenNode.
To go left in depth (i.e. A parent) you would call ->parent

To go down (Same level, next item) you would call ->next
To go up (Same level, previous item) you would call ->prev

I hope this clarifies this for you..

If you want to make this (A. Harder to write initially && B. Easier to use
in the future, use recursion).

Ron Ohmer





-----Original Message-----
From: xml-admin gnome org [mailto:xml-admin gnome org] On Behalf Of shen
peng
Sent: Wednesday, February 11, 2004 4:12 PM
To: xml gnome org
Subject: [xml] how to read the second node?

Hello again ,thank you very much ,I solved last problem but the new question

is coming out :(
the format of xml is like this :
<timetable>
        <direct_train>
                <train number = "suX1">
                        .........
                </train>
                <train number = "suX2">
                        .........
                </train>
        </direct_train>
        <passing1_train>
                <train1 number = "subX1">
                        .........
                </train1>
        </passing1_train>
</timetable>
I can use followed code: doc = xmlParseFile(docname);
                  cur = xmlDocGetRootElement(doc);
                          cur = cur->xmlChildrenNode;
                 cur = cur->next;//this point to <direct_train>;
to read the <timetable> as root node ;<direct_train> as its childrennode,but

when I finish read the data in <direct_train>,I want to read data in 
<passing1_train>, do I need go back to the root node"<timetable>", and 
choose second
childrennode"<passing1_train>"? how can I do ?

thank you in advance
shen.peng

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* 
http://join.msn.com/?page=features/virus

_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml




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