From andrey.v.filimonov at gmail.com Sun Nov 8 08:05:30 2015 From: andrey.v.filimonov at gmail.com (Andrey Filimonov) Date: Sun Nov 8 08:05:39 2015 Subject: [xsde-users] Porting Xerces/XSD project to XSD/e and differences in generated code Message-ID: Hello, I'm trying to port an existing project which uses XSD as a XSD to C++ converter to an embedded environment. So I made an attempt to replace code, generated by XSD, to code, produced by XSD/e, keeping the rest of implementation as is. The attempt failed due to differences in code generated by XSD and XSD/e. I'm now trying to udnerstand is these differences are becasue of core features of XSD and XSD/e or i missed something in XSD/e configuration and these differences can be eliminated. I'm trying to compile a somewhat XSD containing these relevant parts: The starting time for the activity, data, or state change Both XSD and XSD/e produce a named type called dtstart, but the content is different. For XSD it's class dtstart: public ::xml_schema::type { public: // date-time // typedef ::icalendar_2_0::DateTimeType date_time_type; typedef ::xsd::cxx::tree::traits< date_time_type, char > date_time_traits; const date_time_type& date_time () const; date_time_type& date_time (); void date_time (const date_time_type& x); void date_time (::std::auto_ptr< date_time_type > p); // Constructors. // dtstart (const date_time_type&); dtstart (::std::auto_ptr< date_time_type >); dtstart (const ::xercesc::DOMElement& e, ::xml_schema::flags f = 0, ::xml_schema::container* c = 0); dtstart (const dtstart& x, ::xml_schema::flags f = 0, ::xml_schema::container* c = 0); virtual dtstart* _clone (::xml_schema::flags f = 0, ::xml_schema::container* c = 0) const; dtstart& operator= (const dtstart& x); virtual ~dtstart (); // Implementation. // protected: void parse (::xsd::cxx::xml::dom::parser< char >&, ::xml_schema::flags); protected: ::xsd::cxx::tree::one< date_time_type > date_time_; }; For XSD/e it's class dtstart { public: dtstart (); dtstart (const dtstart&); dtstart& operator= (const dtstart&); ~dtstart (); // date-time // const ::icalendar_2_0::DateTimeType& date_time () const; ::icalendar_2_0::DateTimeType& date_time (); void date_time (const ::icalendar_2_0::DateTimeType&); private: ::icalendar_2_0::DateTimeType date_time_; }; The difference breaking the further project compilation is in XSD/e's output not containing a constructor for constructing from DateTimeType while XSD's version do contain. Is there a way to eliminate such a difference? XSD code originally is generated with the following options: cxx-tree --file-per-type --generate-serialization --generate-polymorphic --polymorphic-type-all The XSD/e code is generated with cxx-hybrid --file-per-type --generate-polymorphic --no-stl --no-exceptions --custom-allocator --no-iostream --no-long-long --generate-serializer --generate-parser --suppress-serializer-val Andrey. From boris at codesynthesis.com Mon Nov 9 10:57:33 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Nov 9 10:57:31 2015 Subject: [xsde-users] Porting Xerces/XSD project to XSD/e and differences in generated code In-Reply-To: References: Message-ID: Hi Andrey, Andrey Filimonov writes: > So I made an attempt to replace code, generated by XSD, to code, > produced by XSD/e, keeping the rest of implementation as is. > > The attempt failed due to differences in code generated by XSD and XSD/e. XSD and XSD/e mappings are completely different. There is no way to use both from the same, unmodified, client code except maybe for really trivial cases. This is also not a gratuitous incompatibility: XSD has more features, is more powerful, flexible, and convenient. However, you pay for that with larger footprint and slightly worse performance, compared to XSD/e. While XSD/e is not as powerful as XSD, it is smaller, faster and external dependency-free. It was also specifically designed for working in resource-constrained environments, such as mobile and embedded systems. If you need to target both general-purpose and mobile/embedded platforms, then the recommended approach is to use XSD/e for both. Boris From Hartmut.Nebelung at baslerweb.com Thu Nov 12 05:15:23 2015 From: Hartmut.Nebelung at baslerweb.com (Nebelung, Hartmut) Date: Thu Nov 12 05:15:29 2015 Subject: [xsde-users] Failing to retrieve embedded xml-fragments Message-ID: <9b69be90ea1d4eacbd5fe950ffa08a26@ahr205s.basler.corp> Hi, I am failing to retrieve data of this type: For example: 123 bla blub I do get callbacks for element nodes, but not for the content. resulting in < MyFavourite />< AnotherNode< WithSubNode />< WithSubNode /> /> How can I retrieve the complete content? Regards Hartmut -- Hartmut Nebelung Software Developer Basler AG An der Strusbek 60-62 22926 Ahrensburg Germany Tel. +49 4102 463 388 Fax +49 4102 463 46 388 Hartmut.Nebelung@baslerweb.com www.baslerweb.com Management board: Dr.-Ing. Dietmar Ley (CEO) ? John P. Jennings ? Arndt Bake ? Hardy Mehl Chairman of the supervisory board: Norbert Basler Basler AG ? Amtsgericht L?beck HRB 4090 ? Ust-IdNr.: DE 135 098 121 ? Steuer-Nr.: 30 292 04497 ? WEEE-Reg.-Nr. DE 83888045 From boris at codesynthesis.com Thu Nov 12 10:10:14 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Nov 12 10:10:11 2015 Subject: [xsde-users] Failing to retrieve embedded xml-fragments In-Reply-To: <9b69be90ea1d4eacbd5fe950ffa08a26@ahr205s.basler.corp> References: <9b69be90ea1d4eacbd5fe950ffa08a26@ahr205s.basler.corp> Message-ID: Hi Hartmut, Nebelung, Hartmut writes: > I do get callbacks for element nodes, but not for the content. Can you show your parser implementation for AnotherNode where you expect to get the content callback? Also, you may want to check the 'cxx/parser/wildcard' example in the XSD/e distribution to see if you are doing something differently. Boris From Hartmut.Nebelung at baslerweb.com Thu Nov 12 11:14:04 2015 From: Hartmut.Nebelung at baslerweb.com (Nebelung, Hartmut) Date: Thu Nov 12 11:14:16 2015 Subject: [xsde-users] Failing to retrieve embedded xml-fragments In-Reply-To: References: <9b69be90ea1d4eacbd5fe950ffa08a26@ahr205s.basler.corp> Message-ID: ===================================================================== class ExtensionType_pskel: public ::xsde::cxx::parser::validating::complex_content { public: // Parser callbacks. Override them in your implementation. // // virtual void // pre (); // Elements. // virtual void post_ExtensionType (); // Constructor. // ExtensionType_pskel (); // Implementation details. // protected: ExtensionType_pskel* ExtensionType_impl_; ExtensionType_pskel (ExtensionType_pskel*, void*); protected: virtual bool _start_element_impl (const ::xsde::cxx::ro_string&, const ::xsde::cxx::ro_string&); virtual bool _end_element_impl (const ::xsde::cxx::ro_string&, const ::xsde::cxx::ro_string&); public: struct v_state_descr_ { void (::GENAPI_NAMESPACE::Version_1_1::ExtensionType_pskel::*func) ( unsigned long&, unsigned long&, const ::xsde::cxx::ro_string&, const ::xsde::cxx::ro_string&, bool); unsigned long state; unsigned long count; }; struct v_state_ { v_state_descr_ data[2UL]; unsigned long size; }; protected: v_state_ v_state_first_; ::xsde::cxx::stack v_state_stack_; virtual void _pre_e_validate (); virtual void _post_e_validate (); void sequence_0 (unsigned long&, unsigned long&, const ::xsde::cxx::ro_string&, const ::xsde::cxx::ro_string&, bool); }; ============================================================== class ExtensionType_pimpl: public ExtensionType_pskel { public: std::string content; unsigned m_Indent; private: unsigned m_ElementDepth; unsigned m_StartIndex; unsigned m_EndIndex; const char*m_pStartElementSequence; const char*m_pEndElementSequence; public: ExtensionType_pimpl(); virtual void reset(); virtual void pre (); virtual void post_ExtensionType (); #ifndef XSDE_POLYMORPHIC virtual void _start_any_element(const xml_schema::ro_string& ns, const xml_schema::ro_string& name); #else virtual void _start_any_element(const xml_schema::ro_string& ns, const xml_schema::ro_string& name, const char*); #endif virtual void _end_any_element(const xml_schema::ro_string& ns, const xml_schema::ro_string& name); virtual void _any_characters(xml_schema::ro_string& c); virtual void _any_attribute(const xml_schema::ro_string& ns, const xml_schema::ro_string& name, const xml_schema::ro_string& value); }; ============================================================= Is there single callback returning the complete content of the Extension node? I would like to preserve comments and indentation as well. Thanks Hartmut -- Hartmut Nebelung Software Developer Basler AG An der Strusbek 60-62 22926 Ahrensburg Germany Tel. +49 4102 463 388 Fax +49 4102 463 46 388 Hartmut.Nebelung@baslerweb.com www.baslerweb.com Management board: Dr.-Ing. Dietmar Ley (CEO) ? John P. Jennings ? Arndt Bake ? Hardy Mehl Chairman of the supervisory board: Norbert Basler Basler AG ? Amtsgericht L?beck HRB 4090 ? Ust-IdNr.: DE 135 098 121 ? Steuer-Nr.: 30 292 04497 ? WEEE-Reg.-Nr. DE 83888045 > -----Original Message----- > From: xsde-users-bounces@codesynthesis.com [mailto:xsde-users- > bounces@codesynthesis.com] On Behalf Of Boris Kolpackov > Sent: Thursday, November 12, 2015 4:10 PM > To: Nebelung, Hartmut > Cc: xsde-users@codesynthesis.com > Subject: Re: [xsde-users] Failing to retrieve embedded xml-fragments > > Hi Hartmut, > > Nebelung, Hartmut writes: > > > I do get callbacks for element nodes, but not for the content. > > Can you show your parser implementation for AnotherNode where you > expect to get the content callback? > > Also, you may want to check the 'cxx/parser/wildcard' example in > the XSD/e distribution to see if you are doing something differently. > > Boris From boris at codesynthesis.com Fri Nov 13 09:42:53 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Nov 13 09:42:49 2015 Subject: [xsde-users] Failing to retrieve embedded xml-fragments In-Reply-To: References: <9b69be90ea1d4eacbd5fe950ffa08a26@ahr205s.basler.corp> Message-ID: Hi Hartmut, Nebelung, Hartmut writes: > virtual void > _any_characters(xml_schema::ro_string& c); Ok, just to confirm, the behavior you are observing is that you get the _start_any_element() and _end_any_element() calls for "WithSubNode" but not _any_characters() between them? Can you show the implementation of your _any_characters()? > Is there single callback returning the complete content of the > Extension node? I would like to preserve comments and indentation > as well. No, this content is parsed as XML and comments, whitespaces are discarded. Boris From andrey.v.filimonov at gmail.com Tue Nov 17 06:19:19 2015 From: andrey.v.filimonov at gmail.com (Andrey Filimonov) Date: Tue Nov 17 06:19:26 2015 Subject: [xsde-users] Using auto_ptr for passing shared objects Message-ID: Hello, I continue comparing parser/serializer implementations created by XSD and XSDe. Code generated by XSD uses auto_ptr to pass shared objects. In spite of the fact that the implementation is generated by XSDe without --no-stl parameter, raw pointers are used to pass objects in the same circumstances. Is there a way to create code using auto_ptr instead of raw pointers? Andrey. From Hartmut.Nebelung at baslerweb.com Tue Nov 17 15:14:34 2015 From: Hartmut.Nebelung at baslerweb.com (Nebelung, Hartmut) Date: Tue Nov 17 15:14:38 2015 Subject: [xsde-users] Failing to retrieve embedded xml-fragments In-Reply-To: References: <9b69be90ea1d4eacbd5fe950ffa08a26@ahr205s.basler.corp> Message-ID: <24578e2322dd459cabda066043ac57cf@ahr206s.basler.corp> Hi Boris, I finally found out, it was simple c++ bug of mine: > > virtual void > > _any_characters(xml_schema::ro_string& c); The signature does not match the definition. Adding the missing const fixes the problem. Thanks Hartmut -- Hartmut Nebelung Software Developer Basler AG An der Strusbek 60-62 22926 Ahrensburg Germany Tel. +49 4102 463 388 Fax +49 4102 463 46 388 Hartmut.Nebelung@baslerweb.com www.baslerweb.com Management board: Dr.-Ing. Dietmar Ley (CEO) ? John P. Jennings ? Arndt Bake ? Hardy Mehl Chairman of the supervisory board: Norbert Basler Basler AG ? Amtsgericht L?beck HRB 4090 ? Ust-IdNr.: DE 135 098 121 ? Steuer-Nr.: 30 292 04497 ? WEEE-Reg.-Nr. DE 83888045 > -----Original Message----- > From: Boris Kolpackov [mailto:boris@codesynthesis.com] > Sent: Friday, November 13, 2015 3:43 PM > To: Nebelung, Hartmut > Cc: xsde-users@codesynthesis.com > Subject: Re: [xsde-users] Failing to retrieve embedded xml-fragments > > Hi Hartmut, > > Nebelung, Hartmut writes: > > > virtual void > > _any_characters(xml_schema::ro_string& c); > > Ok, just to confirm, the behavior you are observing is that you > get the _start_any_element() and _end_any_element() calls for > "WithSubNode" but not _any_characters() between them? Can you > show the implementation of your _any_characters()? > > > > Is there single callback returning the complete content of the > > Extension node? I would like to preserve comments and indentation > > as well. > > No, this content is parsed as XML and comments, whitespaces are > discarded. > > Boris From boris at codesynthesis.com Wed Nov 18 10:22:11 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Nov 18 10:22:16 2015 Subject: [xsde-users] Using auto_ptr for passing shared objects In-Reply-To: References: Message-ID: Hi Andrey, Andrey Filimonov writes: > I continue comparing parser/serializer implementations created by XSD and > XSDe. Just note, XSD doesn't really have a serializer mapping. > Code generated by XSD uses auto_ptr to pass shared objects. > In spite of the fact that the implementation is generated by XSDe without > --no-stl parameter, raw pointers are used to pass objects in the same > circumstances. You can use a type map to make the parser interface pass objects as smart pointers. Boris From andrey.v.filimonov at gmail.com Wed Nov 18 23:52:05 2015 From: andrey.v.filimonov at gmail.com (Andrey Filimonov) Date: Wed Nov 18 23:52:13 2015 Subject: [xsde-users] Using auto_ptr for passing shared objects In-Reply-To: References: Message-ID: Hi Boris, Thanks for the answers. Is there a way to use typemaps in hybrid mode? Andrey. 2015-11-18 18:22 GMT+03:00 Boris Kolpackov : > Hi Andrey, > > Andrey Filimonov writes: > > > I continue comparing parser/serializer implementations created by XSD and > > XSDe. > > Just note, XSD doesn't really have a serializer mapping. > > > > Code generated by XSD uses auto_ptr to pass shared objects. > > In spite of the fact that the implementation is generated by XSDe without > > --no-stl parameter, raw pointers are used to pass objects in the same > > circumstances. > > You can use a type map to make the parser interface pass objects > as smart pointers. > > Boris > From boris at codesynthesis.com Thu Nov 19 09:13:05 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Nov 19 09:13:07 2015 Subject: [xsde-users] Using auto_ptr for passing shared objects In-Reply-To: References: Message-ID: Hi Andrey, Andrey Filimonov writes: > Is there a way to use typemaps in hybrid mode? The C++/Hybrid mapping uses type maps internally, since it provides the implementations of the parser/serializer skeletons. Why would you care whether C++/Hybrid uses raw pointers or auto_ptr internally? I think we are wasting time here with you trying to "hint" at what the problem is in one-two sentences and me trying to guess what you meant. I suggest that you show a concrete code fragment and point to what exactly causes you problems. Boris From andrey.v.filimonov at gmail.com Fri Nov 20 02:47:15 2015 From: andrey.v.filimonov at gmail.com (Andrey Filimonov) Date: Fri Nov 20 02:47:23 2015 Subject: [xsde-users] Using auto_ptr for passing shared objects In-Reply-To: References: Message-ID: Hi Boris, You're quite right, the reason why i use equivoques instead of direct question in well defined context is that the question is hard to formulate due to lack of context. As i said i'm trying to port a thing which is built over XSD/Xerces to an embedded environment. The thing contains two layers - syntactic based on XSD/Xerces and semantic. There is no proper insulation between these two thus sematic layer is quite thoughly bound to code produced by XSD. They widely used auto_ptr to get rid of explicit object lifecycle management for the syntactic objects. They could do because syntactic layer allowed them so, i.e. code, produced by XSD assumed you can share lifecycle management responsibilities through autopointers. With XSDe i have raw pointers, thus i have to define who is responsible for creating and destroying objects. Adapting semantic layer to XSDe may be tricky because object ownership isn't obvious at all. In the code not taking care of object lifecycle it's hard to figure out who is owning and who is responsible for what. I have two potential ways out: 1) redesign semantic layer to clealy define ownership 2) if possible make code generated by XSDe rely on auto_ptr instead of raw pointers to let current implementation of semantic layer keep its fuzzy ownership. Option 2 seem to cost much less, but from your last message i understood that sharing objects the way can be done with XSD is not implementable with XSDe. This reduces options list above to item 1. I can put particular examples of differences between code produced by XSD and XSDe, but i don't think they are relevant in this context. Thanks for your explanations. Best wishes, Andrey. 2015-11-19 17:13 GMT+03:00 Boris Kolpackov : > Hi Andrey, > > Andrey Filimonov writes: > > > Is there a way to use typemaps in hybrid mode? > > The C++/Hybrid mapping uses type maps internally, since it provides > the implementations of the parser/serializer skeletons. Why would > you care whether C++/Hybrid uses raw pointers or auto_ptr internally? > > I think we are wasting time here with you trying to "hint" at what the > problem is in one-two sentences and me trying to guess what you meant. > I suggest that you show a concrete code fragment and point to what > exactly causes you problems. > > Boris > From boris at codesynthesis.com Mon Nov 23 08:46:43 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Nov 23 08:46:42 2015 Subject: [xsde-users] Using auto_ptr for passing shared objects In-Reply-To: References: Message-ID: Hi Andrey, Andrey Filimonov writes: > With XSDe i have raw pointers, thus i have to define who is responsible for > creating and destroying objects. Adapting semantic layer to XSDe may be > tricky because object ownership isn't obvious at all. In the code not > taking care of object lifecycle it's hard to figure out who is owning and > who is responsible for what. This is not quite correct. While it may not be obvious from the C++/Hybrid object model interface who owns what (unlike if we used auto_ptr), this is all very well defined in the C++/Hybrid Getting Strated Guide, specically, Section 4.2, "Memory Management". In particular, the object model owns its sub-nodes (just like in C++/Tree). Also, nothing prevents you from owning the whole object model with auto_ptr (in fact, quite a few XSD/e examples do exactly that). You can also "detach" sub-nodes from the object model and manage them with auto_ptr just like in C++/Tree (see --generate-detach). And if you need to attach the node back to the object model, simply use auto_ptr::release() (this is probably the only situation where you have to do a little bit more than in C++/Tree). > 2) if possible make code generated by XSDe rely on auto_ptr instead of raw > pointers to let current implementation of semantic layer keep its fuzzy > ownership. > > Option 2 seem to cost much less, but from your last message i understood > that sharing objects the way can be done with XSD [...] I am not sure what "sharing" you refer to here. With auto_ptr you can only transfer ownership (which is supported in both XSD and XSD/e). Boris From andrey.v.filimonov at gmail.com Sat Nov 28 06:46:37 2015 From: andrey.v.filimonov at gmail.com (Andrey Filimonov) Date: Sat Nov 28 06:46:45 2015 Subject: [xsde-users] Polymorphic type is serialized as based Message-ID: Hello, I'm facing an issue trying to serialize a polymorphic type. It's serialized as the base type. XSDE is compiled with polymorphic support. The serializer is instantiated this way: oadrPayload_saggr oadrPayload_s; oadrPayload_s.pre(*payload); xml_schema::document_simpl doc_s (oadrPayload_s.root_serializer(), oadrPayload_s.root_namespace(), oadrPayload_s.root_name(), true); meaning it's constructed with polymorphic = true; There is The initial analysis From andrey.v.filimonov at gmail.com Sat Nov 28 06:55:09 2015 From: andrey.v.filimonov at gmail.com (Andrey Filimonov) Date: Sat Nov 28 06:55:17 2015 Subject: [xsde-users] Re: Polymorphic type is serialized as based In-Reply-To: References: Message-ID: Sorry for accidentally posting an incomplete message. The full one should have been as follows: > Hello, > I'm facing an issue trying to serialize a polymorphic type. It's > serialized as the base type. > XSDE is compiled with polymorphic support. > > The serializer is instantiated this way: > oadrPayload_saggr oadrPayload_s; oadrPayload_s.pre(*payload); > xml_schema::document_simpl doc_s (oadrPayload_s.root_serializer(), > oadrPayload_s.root_namespace(), oadrPayload_s.root_name(), true); > doc_s.serialize (ss, xml_schema::document_simpl::pretty_print); > oadrPayload_s.post (); > meaning it's constructed with polymorphic = true; > > Payload contains a polymorphic object down the tree. > The initial analysis of the issue: When serializer serializes the polymorphic part it internally tries to set the type of the object. This consequently leads to the following function invocation tree: bool context:: set_type (const char* type) [invokes] const char* context:: lookup_namespace_prefix (const char* ns) [invokes] genxNamespace genxDeclareNamespace(genxWriter w, constUtf8 uri, constUtf8 defaultPref, genxStatus * statusP) Adds given namespace to the writer's namespace list. Then sets ns->declaration to NULL for the allocated genxNamespace [invokes] utf8 genxGetNamespacePrefix(genxNamespace ns) returns NULL as ns->declaration was set to NULL returned NULL makes lookup_namespace_prefix return false; return false makes set_type return false; This further makes serializer serialize the polymorphic type as base type. Is there something i could do a wrong way or this is a serializer problem? Andrey. From boris at codesynthesis.com Mon Nov 30 09:47:22 2015 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Nov 30 09:47:24 2015 Subject: [xsde-users] Re: Polymorphic type is serialized as based In-Reply-To: References: Message-ID: Hi Andrey, Andrey Filimonov writes: > utf8 genxGetNamespacePrefix(genxNamespace ns) > returns NULL as ns->declaration was set to NULL This means you haven't established the namespace-prefix mapping for the namespace that is used in xsi:type (XSD/e does not assign such prefixes automatically): doc_s.add_prefix ("ex", "http://www.example.com/example"); See Section 8.1, "Document Serializer" for details. Boris From andrey.v.filimonov at gmail.com Mon Nov 30 10:12:46 2015 From: andrey.v.filimonov at gmail.com (Andrey Filimonov) Date: Mon Nov 30 10:12:53 2015 Subject: [xsde-users] Re: Polymorphic type is serialized as based In-Reply-To: References: Message-ID: Hi Boris, Do you mean it doesn't assign prefixes specifically when serializing polymorphic types? Because for non polymorphic types it assigns perfectly. Andrey. 30 ????. 2015 ?. 17:47 ???????????? "Boris Kolpackov" < boris@codesynthesis.com> ???????: > Hi Andrey, > > Andrey Filimonov writes: > > > utf8 genxGetNamespacePrefix(genxNamespace ns) > > returns NULL as ns->declaration was set to NULL > > This means you haven't established the namespace-prefix mapping for the > namespace that is used in xsi:type (XSD/e does not assign such prefixes > automatically): > > doc_s.add_prefix ("ex", "http://www.example.com/example"); > > See Section 8.1, "Document Serializer" for details. > > Boris >