Re: [xml] Interating over all children of a given node?
- From: carl douglas convergys com
- To: Gabriel Ambuehl <gabriel_ambuehl buz ch>
- Cc: xml xmlsoft org
- Subject: Re: [xml] Interating over all children of a given node?
- Date: Tue, 12 Jun 2001 10:17:01 -0400
Gabriel Ambuehl <gabriel_ambuehl buz ch>@gnome.org on 06/12/2001 09:10:50
AM
Sent by: xml-admin gnome org
To: xml xmlsoft org
cc:
Subject: [xml] Interating over all children of a given node?
-----BEGIN PGP SIGNED MESSAGE-----
Hello,
I wonder what the easiest way to iterate over all direct children of
a
node is. Is there any possibility to obtain a NodeSet of the children
to allow easy iteration?
I'd suggest using XPath to solve this problem, especially if you're looking
for a particular element, content or attribute.
e.g.
ctxt = xmlXPathNewContext(doc);
ctxt->node = xmlDocGetRootElement(doc);
/* context is set to root element but if set to another node the path would start at that node, e.g.
"node/descendant::*" */
result = xmlXPathEval( BAD_CAST "//*", ctxt);
nset = result->nodesetval;
for(n=0;n < nset->nodeNr; n++) {
/* sanity test */
if(!nset->nodeNr) continue;
/* access the nodes with this pointer: nset->nodeTab[n] */
propValue = xmlGetProp(nset->nodeTab[n], BAD_CAST"type");
}
You can find some tutorials about XML and XPath at http://www.zvon.org
--
NOTICE: The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential. If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]