[xsd-users] solution to the visitor custom function? and regex or custom script?

giuseppe ferrari giuseppe500 at yahoo.it
Sun Jul 7 09:12:56 EDT 2013


hello.
I have a partial solution from your advice that creates a template wrapper  in which implement custom functions.
this is an example of an xsd script that create the forward reference to the custom Wrapper for one type
:
xsd cxx-tree --custom-type contact="xml_schema::CustomWrapper<base_contact>/base_contact" --output-dir ifc contacts.xsd

the solution is partial because i have an xsd(ifc.xsd, an architectural format) with more than 2000 classes and i must create a script or something that change this line:

contact="xml_schema::CustomWrapper<base_contact>/base_contact"

in base of the type for each xsd type, and i don't know how.
I see in the documentation that i can extract the list of the types of the xsd(is true?).
a python script or c script is the only solution? Or I can i do something with the regex?


after that ,i can implement and insert the CustomWrapper in the xsd_schema namespace of the generated code:

template < class T >
    class CustomWrapper : public T
    { 
    public:        
    CustomWrapper (const ::xercesc::DOMElement& e,
                  ::xml_schema::flags f = 0,
                  ::xml_schema::container* c = 0): T (e, f, c){};

    CustomWrapper (const T& x,
                  ::xml_schema::flags f = 0,
                  ::xml_schema::container* c = 0): T (x, f, c){};
        void print(){
        
        
            std::string email= this->email();

            cout << email.c_str();
        };
    };

and , the generated forward reference is like this:

namespace contacts
{
  class base_contact;
  typedef xml_schema::CustomWrapper<base_contact> contact;
  class catalog;
}

now i can call the custom function:

int
main (int argc, char* argv[])
{
  using namespace contacts;

  std::auto_ptr<catalog> c (catalog_ ("contacts.xml"));

  for (catalog::contact_iterator i (c->contact ().begin ());
       i != c->contact ().end ();   i)
  {
      (*i).print();
  }
}

the only problem now is the const/no const iterator and custom member function.
this partial solution Is like your advice?
may be correct ?
and...for create the same things for all the classes of the xsd?
thanks.


More information about the xsd-users mailing list