Re: [xml] Count elements using XmlReader
- From: "Andrew W. Nosenko" <andrew w nosenko gmail com>
- To: "Oliver Heyme" <oheyme gmx de>
- Cc: xml gnome org
- Subject: Re: [xml] Count elements using XmlReader
- Date: Mon, 30 Oct 2006 16:46:46 +0200
On 10/29/06, Oliver Heyme <oheyme gmx de> wrote:
Hi,
I have XML-files doing something like this:
<array>
<item data="..."/>
<item data="..."/>
...
<item data="..."/>
<item data="..."/>
</array>
and I am using the xmlReader!
The problem is that I would like to know how many "item" elements are
between the array-tags!
Is there any possibility to do this without adding a "size"-attribute
to the opening array-tag!
It depends on for what you need such "size".
If it's just for information, then add some counter, reset it to zero
at the <array>, increment on the every <item/> and do what you want at
the </array>.
If "size" id needed for you for pre-allocating C-style array
(something like
item_t array[size];
or
item_t* array = calloc(size, sizeof(item_t));
), then just use dynamically-resizable arrays.
For example, C++ std::vector if you use C++, or GArray or GPtrArray
from Glib if your language is plain C...
--
Andrew W. Nosenko <andrew w nosenko gmail com>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]