From boris at codesynthesis.com Mon Aug 3 08:50:45 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Aug 3 03:53:02 2009 Subject: [xsde-users] Extract remaining subtree In-Reply-To: <200907311648.09678.MarkusK@microsol.ie> References: <200907311648.09678.MarkusK@microsol.ie> Message-ID: Hi Markus, Markus Kohler writes: > given a XML file and using the embedded parser xsde can I retrieve a > certain part of the XML tree as string. Example: > > > > > > > > > > > > The easiest way would be to override the low-level XML parsing callbacks and re-serialize the XML fragment to string, something along these lines: class someelement_pimpl: public someelement_pskel { public: virtual void pre () { str_.clear (); } virtual void _start_element (const xml_schema::ro_string& ns, const xml_schema::ro_string& name) { str_ += "<"; str_ += name; open_ = true; } virtual void _end_element (const xml_schema::ro_string& ns, const xml_schema::ro_string& name) { if (open_) { str_ += "/>"; open_ = false; } else { str_ += ""; } } virtual void _attribute (const xml_schema::ro_string& ns, const xml_schema::ro_string& name, const xml_schema::ro_string& value) { str_ += " "; str_ += name; str_ += " = \""; str_ += value; str_ += "\""; } virtual void _characters (const xml_schema::ro_string& s) { if (open_) { str_ += ">"; open_ = false; } str_ += s; } virtual void post_someelement () { // fragment is in str_ } private: bool open_; string str_; }; Note that this will only work for simple XML which doesn't contain special characters that need escaping. If you need a more robust solution then you can use the underlying XML serializer that is used in the C++/Serializer mapping. See libxsde/xsde/c/genx/ for more information. Boris From tftomsun at streamteam.de Fri Aug 7 20:16:51 2009 From: tftomsun at streamteam.de (Thomas Frenzel (TomSun)) Date: Fri Aug 7 20:17:02 2009 Subject: [xsde-users] enumeration type support Message-ID: <20090808001651.e0c6e1ac@streamteam.de> Hello xsde developers, i am very new in the c++ embedded world. In the past i just coded in .NET languages. So i was searching for a possibility to parse/serialize xml streams/files. So i found xsd/e and was suprised how simple the code generation and usage of the generated code is. There's one thing that i am missing. Why do i have to implement the enum parse/serialization by myself? I would like to get an generated enum for each simple type that derives from string and contains only enumerations. Additionally i would like to have generated serializer/parser classes that does the validation for me (Enum declaration in the schema) (Example snipped of the generated code that i would like to have) enum gender { male, female }; ... virtual ::gender post_gender () { std::string s = post_string (); if(s == "male") return gender::male; else if(s == "female") return gender::female; else // TODO throw exception } Did you already plan something like that? Regards, Tom From boris at codesynthesis.com Mon Aug 10 03:58:16 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Aug 10 04:00:37 2009 Subject: [xsde-users] enumeration type support In-Reply-To: <20090808001651.e0c6e1ac@streamteam.de> References: <20090808001651.e0c6e1ac@streamteam.de> Message-ID: Hi Thomas, Thomas Frenzel (TomSun) writes: > There's one thing that i am missing. Why do i have to implement the > enum parse/serialization by myself? I would like to get an generated > enum for each simple type that derives from string and contains only > enumerations. Additionally i would like to have generated > serializer/parser classes that does the validation for me I agree, handling of enums in C++/Parser and C++/Serializer is somewhat awkward. The problem with the approach you suggested is that conceptually these two mappings don't generate object model types. They only provide parser and serializer skeletons. The object model types are provided, if any, by the application developer. Maybe we could generate a helper enum class inside the generated parser skeleton along with the corresponding callback function. Something like this: class gender_pskel { enum gender { male, female }; virtual void pre (); virtual void value (gender g); virtual void post_gender (); }; In any case, I have added this to my TODO list and will try to come up with a solution for the next release of XSD/e. Thanks for the suggestion! Boris From tftomsun at streamteam.de Mon Aug 10 18:03:17 2009 From: tftomsun at streamteam.de (Thomas Frenzel (TomSun)) Date: Mon Aug 10 18:03:29 2009 Subject: [xsde-users] enumeration type support In-Reply-To: boris.20090810094222@codesynthesis.com Message-ID: <20090810220317.bdefb038@streamteam.de> Hello Boris, thanks for your reply and for putting this issue on your todo list. I know that my code didn't match to the architecture. I just wanted to show how the verification should be implemented, so i copy and pasted some code. In the end the enum should become one of the supported default types like integer, double, string. So, i'm excited now and wait for the next version. :) Bye, Thomas _____ From: Boris Kolpackov [mailto:boris@codesynthesis.com] To: Thomas Frenzel (TomSun) [mailto:tftomsun@streamteam.de] Cc: xsde-users@codesynthesis.com Sent: Mon, 10 Aug 2009 09:58:16 +0200 Subject: Re: [xsde-users] enumeration type support Hi Thomas, Thomas Frenzel (TomSun) writes: > There's one thing that i am missing. Why do i have to implement the > enum parse/serialization by myself? I would like to get an generated > enum for each simple type that derives from string and contains only > enumerations. Additionally i would like to have generated > serializer/parser classes that does the validation for me I agree, handling of enums in C++/Parser and C++/Serializer is somewhat awkward. The problem with the approach you suggested is that conceptually these two mappings don't generate object model types. They only provide parser and serializer skeletons. The object model types are provided, if any, by the application developer. Maybe we could generate a helper enum class inside the generated parser skeleton along with the corresponding callback function. Something like this: class gender_pskel { enum gender { male, female }; virtual void pre (); virtual void value (gender g); virtual void post_gender (); }; In any case, I have added this to my TODO list and will try to come up with a solution for the next release of XSD/e. Thanks for the suggestion! Boris From Duncan.Perrett at elekta.com Tue Aug 18 08:58:54 2009 From: Duncan.Perrett at elekta.com (Duncan.Perrett@elekta.com) Date: Tue Aug 18 09:16:02 2009 Subject: [xsde-users] XSD or XSD/e? Message-ID: Hello, I have an XML document which I want to serialize so that class methods can get and set the XML elements as normal class attributes. I will be using gcc cross compiler (on Redhat EL5) for LynxOS-SE RTOS target environment. My colleague did a bit of investigation and concluded ... "The code generated by the CodeSynthesis compiler is the complete code needed in order to serialize objects based on the defined schema. XSD/e is aimed at embedded applications, using its own library, whilst XSD relies on XML parsers provided by other libraries. For object serialization, this library choice is restricted to Xerces. On closer examiniation, there appears to be no means of serializing an XML document into a class with CodeSynthesis XSD/e; code is only generated for serializing object data to file. CodeSynthesis XSD, however could be used to generate XML data of the required form". Is this true? I notice that XSD/e supports LynxOS but does XSD? Thanks, Duncan From boris at codesynthesis.com Tue Aug 18 10:15:04 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Aug 18 10:14:41 2009 Subject: [xsde-users] XSD or XSD/e? In-Reply-To: References: Message-ID: Hi Duncan, Duncan.Perrett@elekta.com writes: > "The code generated by the CodeSynthesis compiler is the complete code > needed in order to serialize objects based on the defined schema. XSD/e > is aimed at embedded applications, using its own library, whilst XSD > relies on XML parsers provided by other libraries. For object > serialization, this library choice is restricted to Xerces. On closer > examiniation, there appears to be no means of serializing an XML document > into a class with CodeSynthesis XSD/e; code is only generated for > serializing object data to file. CodeSynthesis XSD, however could be used > to generate XML data of the required form". Some of this analysis is not exactly correct. Let me clarify a few things: 1. XSD (or, more precisely, the C++/Tree mapping) consists of three parts: the generated code, the header-only runtime library (libxsd), and the underlying XML parser/serializer (Xerces-C++). 2. XSD/e (again, more precisely, the C++/Hybrid mapping which is similar to C++/Tree but is designed and optimized for embedded systems) consists of two parts: the generated code and the runtime library (libxsde). The runtime library includes a customized versions of XML parser (expat) and serializer (genx). 3. The C++/Hybrid mapping in XSD/e, just like C++/Tree in XSD, is capable of parsing the XML documents to the in-memory object model (C++ classes) and serializing this object model back to XML. > I notice that XSD/e supports LynxOS but does XSD? There is a way to use XSD on LynxOS but the procedure for building Xerces-C++ is quite complex (we have built it once on LynxOS 4.2 for a client). So unless you have strong reasons to prefer XSD, I suggest that you go with XSD/e. It has been tested and is fully supported on LynxOS 4.2 and 5.0. Let me know if you have any further questions. Boris From Duncan.Perrett at elekta.com Tue Aug 18 12:29:23 2009 From: Duncan.Perrett at elekta.com (Duncan.Perrett@elekta.com) Date: Tue Aug 18 12:55:26 2009 Subject: [xsde-users] XSD or XSD/e? In-Reply-To: References: Message-ID: Thank you Boris. From: Boris Kolpackov To: Duncan.Perrett@elekta.com Cc: xsde-users@codesynthesis.com Date: 18/08/2009 15:14 Subject: Re: [xsde-users] XSD or XSD/e? Hi Duncan, Duncan.Perrett@elekta.com writes: > "The code generated by the CodeSynthesis compiler is the complete code > needed in order to serialize objects based on the defined schema. XSD/e > is aimed at embedded applications, using its own library, whilst XSD > relies on XML parsers provided by other libraries. For object > serialization, this library choice is restricted to Xerces. On closer > examiniation, there appears to be no means of serializing an XML document > into a class with CodeSynthesis XSD/e; code is only generated for > serializing object data to file. CodeSynthesis XSD, however could be used > to generate XML data of the required form". Some of this analysis is not exactly correct. Let me clarify a few things: 1. XSD (or, more precisely, the C++/Tree mapping) consists of three parts: the generated code, the header-only runtime library (libxsd), and the underlying XML parser/serializer (Xerces-C++). 2. XSD/e (again, more precisely, the C++/Hybrid mapping which is similar to C++/Tree but is designed and optimized for embedded systems) consists of two parts: the generated code and the runtime library (libxsde). The runtime library includes a customized versions of XML parser (expat) and serializer (genx). 3. The C++/Hybrid mapping in XSD/e, just like C++/Tree in XSD, is capable of parsing the XML documents to the in-memory object model (C++ classes) and serializing this object model back to XML. > I notice that XSD/e supports LynxOS but does XSD? There is a way to use XSD on LynxOS but the procedure for building Xerces-C++ is quite complex (we have built it once on LynxOS 4.2 for a client). So unless you have strong reasons to prefer XSD, I suggest that you go with XSD/e. It has been tested and is fully supported on LynxOS 4.2 and 5.0. Let me know if you have any further questions. Boris From boris at codesynthesis.com Wed Aug 19 08:58:12 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Aug 19 08:57:33 2009 Subject: [xsde-users] XSD or XSD/e? In-Reply-To: References: Message-ID: Hi Duncan, In the future please keep your replies CC'ed to the xsde-users mailing list. This way other developers who may have experienced a similar problem can provide you with a solution. Plus questions and answers will be archived and available to others with similar problems. See the posting guidelines for more information: http://www.codesynthesis.com/support/posting-guidelines.xhtml Duncan.Perrett@elekta.com writes: > Another question on XML Data Binding for you! > > If I have an XML file which contains 200 elements like this ... > > motor1 > motor2 > - - > - - > motor200 > > Will the serialization result in C++ methods like > > getMotor1() > getMotor2() > > and > > setMotor1() > setMotor2() ? > > > I assume that it what the CodeSynthesis XSD/e will produce for me. Yes, something along these lines. > My problem is that I really would prefer to use a loop in the application, > eg > > for (i=0; i { > getMotor(i); > } > > Otherwise I've got to call getMotor1(), getMotor2() 200 times > consecutively! No, there is no automatic way to get such a custom API. Also note that it will only be useful if all your motorN elements are of the same type. Otherwise, it is not clear what getMotor(i) would return. If you really need this kind of API and all motor elements are of the same type, it is easy to write a small (C++) program which will generated an adapter function, something along these lines: MotorType getMotor (int i) { switch (i) { case 1: return getMotor1 (); case 2: return getMotor2 (); ... case 200: return getMotor200 (); } } Boris From swati_gaur at yahoo.com Thu Aug 20 01:16:05 2009 From: swati_gaur at yahoo.com (swati gaur) Date: Thu Aug 20 01:16:12 2009 Subject: [xsde-users] Problem in QNX Message-ID: <956760.26896.qm@web50806.mail.re2.yahoo.com> Hi, ?I have sent this mail to you twice before but got no reply regarding this... ? > I? have downloaded xsde-3.1.0-i686-linux-gnu.tar and > trying to create code using hello.xsd schema file in QNX. I > am using the command" xsde cxx-parser hello.xsd" to produce > produces two C++ files: hello-pskel.hxx? and > hello-pskel.cxx but i get an error : xsde : can't access > shared library. > > What could be the problem...Please Help > ? ? ? From boris at codesynthesis.com Thu Aug 20 02:18:24 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 20 02:17:36 2009 Subject: [xsde-users] Problem in QNX In-Reply-To: <956760.26896.qm@web50806.mail.re2.yahoo.com> References: <956760.26896.qm@web50806.mail.re2.yahoo.com> Message-ID: Hi Swati, swati gaur writes: > Hi, > ?I have sent this mail to you twice before but got no reply > regarding this... I replied to both your emails but it seems you haven't gotten them for some reason. Please see: http://www.codesynthesis.com/pipermail/xsde-users/2009-May/000110.html http://www.codesynthesis.com/pipermail/xsde-users/2009-June/000115.html I am going to also send you a private email from a Yahoo account to make sure you get it this time. Boris From Duncan.Perrett at elekta.com Fri Aug 21 05:57:46 2009 From: Duncan.Perrett at elekta.com (Duncan.Perrett@elekta.com) Date: Fri Aug 21 06:12:52 2009 Subject: [xsde-users] Erroneous commands in Getting Started Guide? Message-ID: I have followed the Embedded C++/Hybrid Mapping Getting Started Guide. I think there are missing parts to the compile and link commands in the document. Where are hello.cxx and hello.o? 2.4 Compiling and Running After saving our application from the previous section in driver.cxx, we are ready to compile our first program and run it on the test XML document. On UNIX this can be done with the following commands: $ c++ -I.../libxsde -c driver.cxx hello-pskel.cxx hello-pimpl.cxx $ c++ -o driver driver.o hello-pskel.o hello-pimpl.o \ .../libxsde/xsde/libxsde.a $ ./driver hello.xml Hello, sun! Hello, moon! Hello, world! Here .../libxsde represents the path to the libxsde directory in the XSD/e distribution. Duncan From boris at codesynthesis.com Fri Aug 21 06:27:42 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Aug 21 06:27:30 2009 Subject: [xsde-users] Erroneous commands in Getting Started Guide? In-Reply-To: References: Message-ID: Hi Duncan, Duncan.Perrett@elekta.com writes: > I think there are missing parts to the compile and link commands in the > document. > Where are hello.cxx and hello.o? Yes, the command lines should include these files. I have fixed this and uploaded the new version of the documentation. Thanks for reporting this! Boris From boris at codesynthesis.com Thu Aug 27 09:47:50 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Aug 27 09:46:32 2009 Subject: [xsde-users] Re: Problem in QNX In-Reply-To: <795832.25688.qm@web112512.mail.gq1.yahoo.com> References: <795832.25688.qm@web112512.mail.gq1.yahoo.com> Message-ID: Hi Swati, [I CC'ed xsde-users to my reply.] swati gaur writes: > I was not able to? generate C++ files on QNX, so I was doing the same > thing as you told..but i was just wondering why its not generating in > QNX. After getting C++ files in windows, everything works fine in QNX. > Isn't there a seperate package ( like xsde-3.1.0-i686-linux-gnu.tar > for linux) for QNX also.. as XSD/e supports this platform. There are two parts to XSD/e: the XSD/e compiler (xsde) and the runtime library (libxsde) plus generated code. The runtime library and generated code are specifically written to be minimal and highly-portable. As a result, they can be compiled and used on a wide range of embedded targets, including QNX. The XSD/e compiler, on the other hand, is quite a bit more complex and has several dependencies that are not easy to build for embedded targets (for example, Boost and Xerces-C++). This is normally not a problem since for most embedded systems the development is done in a cross-compilation environment. That is, the embedded application is developed and compiled on a general-purpose system, such as Windows or Linux, and then executed on the embedded target. QNX (and older versions of LynxOS) is special in that it also supports the native development environment. Unfortunately it is still not easy to build the XSD/e compiler for it. It may be possible but it will definitely be time consuming so we can attempt it only if there is sufficient demand or commercial interest. So far you are the only one who seems to be interested. Boris