AW: [xsd-users] How to iterate different childs of a node together

Thomas Müller tm at go-td.de
Wed Mar 29 15:40:56 EST 2006


Hi Boris,

iterating over the base type would be the nicest solution. Using
dynamic_cast it should be possible to get to the native type. On the other
hand this would add another sequence to each node... Could this be an option
to generate this?

I looked at the DOM approach, but my problem was - you guess - to get back
to the tree nodes. The subitems each have more nested items that need to be
processed, so I was stuck. Thus getting back to the tree nodes would be of
great help.

Thanks,
Thomas

-----Ursprüngliche Nachricht-----
Von: Boris Kolpackov [mailto:boris at codesynthesis.com] 
Gesendet: Mittwoch, 29. März 2006 20:01
An: Thomas Müller
Cc: xsd-users at codesynthesis.com
Betreff: Re: [xsd-users] How to iterate different childs of a node together

Hi Thomas,

Thomas Müller <th.mueller at weisang.com> writes:

> I have an element that basically looks like this:
>
> 	<xs:element name="item">
> 	     	<xs:complexType>
>             	<xs:choice minOccurs="0" maxOccurs="unbounded">
>                   	<xs:element name="subitem1">
> 					<xs:complexType>
> 						...
>                     		</xs:complexType>
>                   	</xs:element>
> 	                  <xs:element name="subitem2">
>       				<xs:complexType>
> 						....
> 					</xs:complexType>
>                   	</xs:element>
> 			</xs:choice>
> 		</xs:complexType>
> 	</xs:element>
>
> The generated iterators allow to iterate over all nodes of type 
> subitem1 and
> subitem2 separately.
> Is there an easy way to iterate over all subitem-nodes (subitem1 and
> subitem2) in the sequence of their occurence?

The problem with such an iteration is that it is not clear what type it
should be based on. The only type that comes to mind is xml_schema::type,
from which all schema types derive.

Right now you can associate DOM nodes with your tree nodes (see
examples/cxx/tree/mixed on how to do this). With this, you will be able to
get a DOM node that corresponds to an 'item' and then iterate over all
sub-nodes in the sequence of their occurrence.
Though you won't be able to get "back" to the tree nodes (e.g., 'subitem1'
and 'subitem2') from DOM nodes. I don't, however, see any technical
difficulty in implementing this if somebody needs it (i.e., store a pointer
to xml_schema::type in DOM nodes). So let me know if you need this.


hth,
-boris





More information about the xsd-users mailing list