[xsd-users] xsd:any in parser

Boris Kolpackov boris at codesynthesis.com
Tue May 22 06:58:14 EDT 2007


Hi Jiri,

Jiri Poledna <jiripoledna at seznam.cz> writes:

> Let's say I can implement Reviewer parser in my project, how to connect
> the Reviewer parser to complete parsing process.
> other worlds: I can implement Title parser, I can add it to process by
> "root_parser.Title_parser(title_parser);".
>
> Because I have no method to add Reviewer parser to root_parser, then I
> cannot reach Reviewer parser implementation. I can get data only using
> _any_ methods. Exist some method to skip that "any bridge" and continue
> parsing inside the reviewer as usual way?

Hm, good question. You see, the wildcard can match any number of
elements and XSD has no way to know which one it will. To achieve
what you want you will need to route the parsing events to the
Reviewer parser implementation manually. Here is how your code
might look:


class Reviewer_impl: ...
{
  ...
};


class root_impl: ...
{
public:

  ...

  root_impl (Reviewer_impl& reviewer)
    : reviewer_ (reviewer), depth_ (0)
  {
  }

  virtual void
  _start_any_element (const xml_schema::ro_string& ns,
                      const xml_schema::ro_string& name)
  {
    if (depth_++ > 0)
      reviewer_._start_element (ns, name);
    else
    {
      if (name == "Reviewer" && ns.empty ())
      {
        reviewer_.pre ();
        reviewer_._pre_impl ();
      }
      else
      {
        // Something else in place of the wildcard.
      }
    }
  }

  virtual void
  _end_any_element (const xml_schema::ro_string& ns,
                    const xml_schema::ro_string& name)
  {
    if (--depth_ > 0)
      reviewer_._end_element (ns, name);
    else
    {
      reviewer_._post_impl ();
      reviewer_.post ();
    }
  }

  virtual void
  _any_attribute (const xml_schema::ro_string& ns,
                  const xml_schema::ro_string& name,
                  const xml_schema::ro_string& value)
  {
    reviewer_._attribute (ns, name, value);
  }

  virtual void
  _any_characters (const xml_schema::ro_string& s)
  {
    reviewer_._characters (s);
  }

private:
  Reviewer_impl& reviewer_;
  std::size_t depth_;
};


hth,
-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/20070522/323804d9/attachment.pgp


More information about the xsd-users mailing list