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

Boris Kolpackov boris at codesynthesis.com
Thu Mar 30 04:33:05 EST 2006


Hi Thomas,

Thomas Müller <tm at go-td.de> writes:

> 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?

Yes, I suppose it could be done this way. I am wondering how useful
such a feature would be in general. I think for now we will just
support getting back from DOM nodes (see below). If more people ask
for this, we will consider implementing it.


> 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.

Ok, it was relatively easy to implement. Here are two files you will
need to replace in your 2.0.0 distribution:

http://codesynthesis.com/~boris/tmp/libxsd-2.0.0-dom-backptr.zip

This adds support for getting back from DOM nodes to tree nodes. Here
is how you would use it (from the modified 'mixed' example):


case DOMNode::ELEMENT_NODE:
{
  // Let's get back to a tree node from this DOM node.
  //
  xml_schema::type& t (
    *reinterpret_cast<xml_schema::type*> (
      n->getUserData (xml_schema::tree_node_key)));

  anchor_type& a (dynamic_cast<anchor_type&> (t));

  cout << a << "[" << ref << "]";

  ++ref;
  break;
}


Two things to note:

1. You won't be able to use xml_schema::tree_node_key name until 2.1.0
   is released (in a few weeks). Instead use
   xsd::cxx::tree::user_data_keys::node.

2. You can use static_cast instead of dynamic_cast above if you are sure
   about the type.

Let me know if you run into any problems.

-boris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 652 bytes
Desc: Digital signature
Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20060330/f5fb76a8/attachment.pgp


More information about the xsd-users mailing list