From boris at codesynthesis.com Mon Sep 2 07:41:54 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Sep 2 07:43:36 2013 Subject: [xsd-users] SOAP message serialization using XSD compiler on WSDL In-Reply-To: <1377798207.95052.YahooMailNeo@web194002.mail.sg3.yahoo.com> References: <1377798207.95052.YahooMailNeo@web194002.mail.sg3.yahoo.com> Message-ID: Hi Neeraj, Neeraj Vaidya writes: > I have a WSDL which defines the layout of SOAP messages that will > be exchanged between my application and another. My application is > based on C++. Is there a way to generate serialization code using > xsd compiler ? XSD doesn not directly support WSDL. However, if you factor the message schemas into separate .xsd files (WSDL support defining messages in external schema files), then you can compile them with XSD. You can also compile the SOAP schema for the envelope and parse/ serialize it using XSD. The message in the SOAP envelop will be represented as a wildcard content (xsd:any) so you will need to re-parse/re-serialize them using the classed generated from the message schemas. See the 'wildcard' example for details on how to do this. Boris From patti at nebland.com Mon Sep 2 20:03:58 2013 From: patti at nebland.com (Patti DuPont) Date: Tue Sep 3 05:29:51 2013 Subject: [xsd-users] Problem to transform XML to C++ Message-ID: <7A47C52E-2986-4E21-A25E-CDBAB15078E8@nebland.com> I have a question on using Code Synthesis with multiple xsd files. I have a number of xsd files that have inter-dependencies between them. I generated the hxx and cxx files for all files in the same command, with using the namespace-map option. When I'm compiling my c++ program though, I'm getting errors that items aren't yet declared that are declared in other xsd files. Am I missing an option for xsd, or do I need to list the files in a certain order in my command? ../src/oadr_strm_20a.hxx:414: error: '::energyinterop' has not been declared Thanks for any assistance you might be able to provide me. Thanks, Patti DuPont From boris at codesynthesis.com Tue Sep 3 07:00:52 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Sep 3 07:02:32 2013 Subject: [xsd-users] Problem to transform XML to C++ In-Reply-To: <7A47C52E-2986-4E21-A25E-CDBAB15078E8@nebland.com> References: <7A47C52E-2986-4E21-A25E-CDBAB15078E8@nebland.com> Message-ID: Hi Patti, Patti DuPont writes: > I have a number of xsd files that have inter-dependencies between them. > > [...] > > When I'm compiling my c++ program though, I'm getting errors that items > aren't yet declared that are declared in other xsd files. Looks like you have schemas with circular dependencies that cannot be mapped to C++ in the file-per-schema mode. In such cases you can use the file-per-type mode. See this release announcement for details: http://www.codesynthesis.com/~boris/blog/2008/02/13/codesynthesis-xsd-3-1-0-released/ Boris From patti at nebland.com Tue Sep 3 23:35:33 2013 From: patti at nebland.com (Patti DuPont) Date: Wed Sep 4 02:18:52 2013 Subject: [xsd-users] Problem to transform XML to C++ In-Reply-To: References: <7A47C52E-2986-4E21-A25E-CDBAB15078E8@nebland.com> Message-ID: <69212EB2-A98F-4F6F-89B2-B7CAEC746F92@nebland.com> Thanks - that did the trick! On Sep 3, 2013, at 6:00 AM, Boris Kolpackov wrote: > Hi Patti, > > Patti DuPont writes: > >> I have a number of xsd files that have inter-dependencies between them. >> >> [...] >> >> When I'm compiling my c++ program though, I'm getting errors that items >> aren't yet declared that are declared in other xsd files. > > Looks like you have schemas with circular dependencies that cannot be > mapped to C++ in the file-per-schema mode. In such cases you can use > the file-per-type mode. See this release announcement for details: > > http://www.codesynthesis.com/~boris/blog/2008/02/13/codesynthesis-xsd-3-1-0-released/ > > Boris From erik.sjolund at gmail.com Sat Sep 7 05:21:03 2013 From: erik.sjolund at gmail.com (=?ISO-8859-1?Q?Erik_Sj=F6lund?=) Date: Sat Sep 7 05:21:10 2013 Subject: [xsd-users] small documentation typo Message-ID: To me it looks that it should be a == instead of a != in the following code in the documentation: DOMNode* n = root->_node (); assert (n->getNodeType () != DOMNode::ELEMENT_NODE); DOMElement* re = static_cast (n); Copied from: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#5.1 cheers, Erik Sj?lund From erik.sjolund at gmail.com Sat Sep 7 09:13:11 2013 From: erik.sjolund at gmail.com (=?ISO-8859-1?Q?Erik_Sj=F6lund?=) Date: Sat Sep 7 09:13:19 2013 Subject: [xsd-users] bug in examples/cxx/tree/custom/comments/dom-parse.cxx Message-ID: If you patch the example custom/comments with the attached file patch.txt the comment from the original file people.xml will be preserved in the output from this command: $ ./driver people.xml Joe Dirt 29 John Doe 30 The example source code makes more sense this way, I think. cheers Erik Sj?lund -------------- next part -------------- --- xsd-4.0.0.a12-x86_64-linux-gnu/examples/cxx/tree/custom/comments/dom-parse.cxx 2009-11-05 05:44:29.000000000 +0100 +++ xsd-4.0.0.a12-x86_64-linux-gnu.new/examples/cxx/tree/custom/comments/dom-parse.cxx 2013-09-07 14:57:10.986011322 +0200 @@ -41,7 +41,7 @@ // Discard comment nodes in the document. // - conf->setParameter (XMLUni::fgDOMComments, false); + conf->setParameter (XMLUni::fgDOMComments, true); // Enable datatype normalization. // @@ -92,7 +92,7 @@ xml::dom::auto_ptr parser ( impl->createDOMBuilder (DOMImplementationLS::MODE_SYNCHRONOUS, 0)); - parser->setFeature (XMLUni::fgDOMComments, false); + parser->setFeature (XMLUni::fgDOMComments, true); parser->setFeature (XMLUni::fgDOMDatatypeNormalization, true); parser->setFeature (XMLUni::fgDOMEntities, false); parser->setFeature (XMLUni::fgDOMNamespaces, true); From boris at codesynthesis.com Mon Sep 9 05:26:33 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Sep 9 05:28:11 2013 Subject: [xsd-users] small documentation typo In-Reply-To: References: Message-ID: Hi Erik, Fixed, thanks for the report! Boris From boris at codesynthesis.com Mon Sep 9 05:33:37 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Sep 9 05:35:15 2013 Subject: [xsd-users] bug in examples/cxx/tree/custom/comments/dom-parse.cxx In-Reply-To: References: Message-ID: Hi Erik, Erik Sj?lund writes: > The example source code makes more sense this way, I think. Yes, that's a bug. It is now fixed, thanks for the report! Boris From albert.babinskas at imagingsciences.com Mon Sep 9 09:09:54 2013 From: albert.babinskas at imagingsciences.com (Babinskas, Albert) Date: Mon Sep 9 09:11:23 2013 Subject: [xsd-users] How to add data to xml any type of object Message-ID: Hello, I have an xml any type of object to which I want to add another object. How would I do that? -Albert Please be advised that this email may contain confidential information. If you are not the intended recipient, please notify us by email by replying to the sender and delete this message. The sender disclaims that the content of this email constitutes an offer to enter into, or the acceptance of, any agreement; provided that the foregoing does not invalidate the binding effect of any digital or other electronic reproduction of a manual signature that is included in any attachment. From boris at codesynthesis.com Mon Sep 9 13:33:49 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Sep 9 13:35:29 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Hi Albert, Babinskas, Albert writes: > I have an xml any type of object to which I want to add another > object. How would I do that? Are you referring to XML Schema wildcards (xs:any, xs:anyAttribute)? If so, take a look at the 'wildcard' example in the examples/cxx/tree/ directory in the XSD distribution. Boris From albert.babinskas at imagingsciences.com Mon Sep 9 14:23:22 2013 From: albert.babinskas at imagingsciences.com (Babinskas, Albert) Date: Mon Sep 9 14:23:33 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Hi Boris, Yes, I am using xs:any wildcard. I have reviewed 'wildcard' and 'mixed' examples in cxx/tree/ and I have further questions. My XSD piece looks like this: It does compile, but I cannot get any_sequence, any_iterator or any to appear. I am not sure what I am doing wrong. I did try to compare XSD with the example provided in 'wildcard' and make it identical () But that didn't help. -Albert -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Monday, September 09, 2013 1:34 PM To: Babinskas, Albert Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] How to add data to xml any type of object Hi Albert, Babinskas, Albert writes: > I have an xml any type of object to which I want to add another > object. How would I do that? Are you referring to XML Schema wildcards (xs:any, xs:anyAttribute)? If so, take a look at the 'wildcard' example in the examples/cxx/tree/ directory in the XSD distribution. Boris Please be advised that this email may contain confidential information. If you are not the intended recipient, please notify us by email by replying to the sender and delete this message. The sender disclaims that the content of this email constitutes an offer to enter into, or the acceptance of, any agreement; provided that the foregoing does not invalidate the binding effect of any digital or other electronic reproduction of a manual signature that is included in any attachment. From boris at codesynthesis.com Tue Sep 10 08:14:38 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Sep 10 08:16:16 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Hi Albert, Babinskas, Albert writes: > > > > > > > It does compile, but I cannot get any_sequence, any_iterator or any > to appear. In your case there will be just any() accessors/modifiers since the cardinality is 1. > I am not sure what I am doing wrong. Perhaps you are not compiling your schema with the --generate-wildcard option. See Section 2.12, "Mapping for any and anyAttribute" in the C++/Tree Mapping User Manual: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.12 Boris From albert.babinskas at imagingsciences.com Tue Sep 10 09:06:19 2013 From: albert.babinskas at imagingsciences.com (Babinskas, Albert) Date: Tue Sep 10 09:06:32 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Hi Boris, I realized that yesterday after I have sent the email. I added --generate-wildcard option and I was able to generate accessor and modifier methods for the XSD. I still have the remaining question of how can I add object to this xs:any type? 'Wildcard' example shows that you create 'envelope' object and then get its DOMDocument. I cannot instantiate my object since it requires to pass it DOMElement. How can I create DOMDocument from the XSD? Another example of 'dbxml' shows that you are using XmlManager, but I am not sure where to get that object. -Albert -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Tuesday, September 10, 2013 8:15 AM To: Babinskas, Albert Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] How to add data to xml any type of object Hi Albert, Babinskas, Albert writes: > > > > > > > It does compile, but I cannot get any_sequence, any_iterator or any to > appear. In your case there will be just any() accessors/modifiers since the cardinality is 1. > I am not sure what I am doing wrong. Perhaps you are not compiling your schema with the --generate-wildcard option. See Section 2.12, "Mapping for any and anyAttribute" in the C++/Tree Mapping User Manual: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.12 Boris Please be advised that this email may contain confidential information. If you are not the intended recipient, please notify us by email by replying to the sender and delete this message. The sender disclaims that the content of this email constitutes an offer to enter into, or the acceptance of, any agreement; provided that the foregoing does not invalidate the binding effect of any digital or other electronic reproduction of a manual signature that is included in any attachment. From boris at codesynthesis.com Wed Sep 11 05:57:46 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Sep 11 05:59:24 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Hi Albert, Babinskas, Albert writes: > I still have the remaining question of how can I add object to this > xs:any type? 'Wildcard' example shows that you create 'envelope' > object and then get its DOMDocument. I cannot instantiate my object > since it requires to pass it DOMElement. You don't need to pass DOMDocument when creating your object (this constructor is used internally by XSD for XML parsing). Instead, your object will have a number of other constructors and one of them will take an argument for every required attribute and element (if you don't have any, then it will become the default constructor). That's also how the 'wildcard' example creates a new 'binary' object (driver.cxx:124) and adds it to the envelope. If you are still having trouble instantiating your object, please show us the relevant XML Schema definitions. Boris From albert.babinskas at imagingsciences.com Wed Sep 11 10:30:05 2013 From: albert.babinskas at imagingsciences.com (Babinskas, Albert) Date: Wed Sep 11 10:30:16 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Hi Boris, I got it to work, but the solution doesn't not look elegant. I will provide my XSD and code to show you what I mean. Here is my XSD: And Another XSD snippet: And Here is my code snippet: VixWinXml::file_t annotationFile(xml_schema::base64_binary(fileContent, size)); stringstream sstream; VixWinXml::annotationFile(sstream, annotationFile, localSerializationMap); xsd::cxx::xml::dom::auto_ptr domPtr = ObjectParser::parseToDom(sstream, "id", false); add_namespace(domPtr.get(), domPtr->getDocumentElement(), "http://VixWinXml"); xercesc::DOMElement& e = *domPtr->getDocumentElement(); schema1::datawarehouse::brandXml_t b(e, xml_schema::flags::dont_validate, 0); b.any().release(); b.any(e); I don't get default constructor created for me by Codesynthesis XSD. I have these 3 constructors that are created: // Constructors. brandXml_t (const ::xercesc::DOMElement&); brandXml_t (const ::xercesc::DOMElement& e, ::xml_schema::flags f = 0, ::xml_schema::container* c = 0); brandXml_t (const brandXml_t& x, ::xml_schema::flags f = 0, ::xml_schema::container* c = 0); Ideally I would like to add my object (annotationFile) to add to brandXml_t any. If I would have default empty constructor, I could add any object without "adding namespaces". I could write constructor myself, but I would like Codesynthesis to generate it. -Albert -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Wednesday, September 11, 2013 5:58 AM To: Babinskas, Albert Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] How to add data to xml any type of object Hi Albert, Babinskas, Albert writes: > I still have the remaining question of how can I add object to this > xs:any type? 'Wildcard' example shows that you create 'envelope' > object and then get its DOMDocument. I cannot instantiate my object > since it requires to pass it DOMElement. You don't need to pass DOMDocument when creating your object (this constructor is used internally by XSD for XML parsing). Instead, your object will have a number of other constructors and one of them will take an argument for every required attribute and element (if you don't have any, then it will become the default constructor). That's also how the 'wildcard' example creates a new 'binary' object (driver.cxx:124) and adds it to the envelope. If you are still having trouble instantiating your object, please show us the relevant XML Schema definitions. Boris Please be advised that this email may contain confidential information. If you are not the intended recipient, please notify us by email by replying to the sender and delete this message. The sender disclaims that the content of this email constitutes an offer to enter into, or the acceptance of, any agreement; provided that the foregoing does not invalidate the binding effect of any digital or other electronic reproduction of a manual signature that is included in any attachment. From Chris.Delnooz at hydrix.com Wed Sep 11 17:16:02 2013 From: Chris.Delnooz at hydrix.com (Chris Delnooz) Date: Wed Sep 11 17:16:18 2013 Subject: [SPAM - Invalid Headers] - RE: [xsd-users] How to add data to xml any type of object - Email found in subject In-Reply-To: References: Message-ID: <1ABD3AB5D5D0DC439E0C9617AC6DF683B9C16C@ALLEXCH.alloratech.local> Hi Albert, You can have XSD generate a default constructor for each of the types specified in your XSD by adding --generate-default-ctor to the command line. Just be aware that the generated default constructor does not initialize the required attributes of your class, so you have to make sure not to access them without setting them first. Regards Chris -----Original Message----- From: xsd-users-bounces@codesynthesis.com [mailto:xsd-users-bounces@codesynthesis.com] On Behalf Of Babinskas, Albert Sent: Thursday, 12 September 2013 12:30 AM To: xsd-users@codesynthesis.com Subject: [SPAM - Invalid Headers] - RE: [xsd-users] How to add data to xml any type of object - Email found in subject Hi Boris, I got it to work, but the solution doesn't not look elegant. I will provide my XSD and code to show you what I mean. Here is my XSD: And Another XSD snippet: And Here is my code snippet: VixWinXml::file_t annotationFile(xml_schema::base64_binary(fileContent, size)); stringstream sstream; VixWinXml::annotationFile(sstream, annotationFile, localSerializationMap); xsd::cxx::xml::dom::auto_ptr domPtr = ObjectParser::parseToDom(sstream, "id", false); add_namespace(domPtr.get(), domPtr->getDocumentElement(), "http://VixWinXml"); xercesc::DOMElement& e = *domPtr->getDocumentElement(); schema1::datawarehouse::brandXml_t b(e, xml_schema::flags::dont_validate, 0); b.any().release(); b.any(e); I don't get default constructor created for me by Codesynthesis XSD. I have these 3 constructors that are created: // Constructors. brandXml_t (const ::xercesc::DOMElement&); brandXml_t (const ::xercesc::DOMElement& e, ::xml_schema::flags f = 0, ::xml_schema::container* c = 0); brandXml_t (const brandXml_t& x, ::xml_schema::flags f = 0, ::xml_schema::container* c = 0); Ideally I would like to add my object (annotationFile) to add to brandXml_t any. If I would have default empty constructor, I could add any object without "adding namespaces". I could write constructor myself, but I would like Codesynthesis to generate it. -Albert -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Wednesday, September 11, 2013 5:58 AM To: Babinskas, Albert Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] How to add data to xml any type of object Hi Albert, Babinskas, Albert writes: > I still have the remaining question of how can I add object to this > xs:any type? 'Wildcard' example shows that you create 'envelope' > object and then get its DOMDocument. I cannot instantiate my object > since it requires to pass it DOMElement. You don't need to pass DOMDocument when creating your object (this constructor is used internally by XSD for XML parsing). Instead, your object will have a number of other constructors and one of them will take an argument for every required attribute and element (if you don't have any, then it will become the default constructor). That's also how the 'wildcard' example creates a new 'binary' object (driver.cxx:124) and adds it to the envelope. If you are still having trouble instantiating your object, please show us the relevant XML Schema definitions. Boris Please be advised that this email may contain confidential information. If you are not the intended recipient, please notify us by email by replying to the sender and delete this message. The sender disclaims that the content of this email constitutes an offer to enter into, or the acceptance of, any agreement; provided that the foregoing does not invalidate the binding effect of any digital or other electronic reproduction of a manual signature that is included in any attachment. From boris at codesynthesis.com Thu Sep 12 04:44:25 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Sep 12 04:46:02 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Hi Albert, Babinskas, Albert writes: > > > > > > > [...] > > I don't get default constructor created for me by Codesynthesis XSD. Yes, I see now. Your brandXml_t has a single required any wildcard. The first constructor that you have shown expects you to pass the value for that wildcard which, as you have shown, is awkward to create. As Chris suggested, the best way to resolve this is to generate the default constructor with the --generate-default-ctor option. Once this is done, you can populate a brandXml_t instance pretty much the same way as in the 'wildcard' example: brandXml_t xml; DOMDocument& doc (xml.dom_document ()); DOMElement* e (doc.createElementSN (...)); // Serialize content to e. xml.any (e); Boris From albert.babinskas at imagingsciences.com Thu Sep 12 08:16:57 2013 From: albert.babinskas at imagingsciences.com (Babinskas, Albert) Date: Thu Sep 12 08:17:17 2013 Subject: [xsd-users] How to add data to xml any type of object In-Reply-To: References: Message-ID: Thank you Boris and Chris. -Albert -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Thursday, September 12, 2013 4:44 AM To: Babinskas, Albert Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] How to add data to xml any type of object Hi Albert, Babinskas, Albert writes: > > > > > > > [...] > > I don't get default constructor created for me by Codesynthesis XSD. Yes, I see now. Your brandXml_t has a single required any wildcard. The first constructor that you have shown expects you to pass the value for that wildcard which, as you have shown, is awkward to create. As Chris suggested, the best way to resolve this is to generate the default constructor with the --generate-default-ctor option. Once this is done, you can populate a brandXml_t instance pretty much the same way as in the 'wildcard' example: brandXml_t xml; DOMDocument& doc (xml.dom_document ()); DOMElement* e (doc.createElementSN (...)); // Serialize content to e. xml.any (e); Boris Please be advised that this email may contain confidential information. If you are not the intended recipient, please notify us by email by replying to the sender and delete this message. The sender disclaims that the content of this email constitutes an offer to enter into, or the acceptance of, any agreement; provided that the foregoing does not invalidate the binding effect of any digital or other electronic reproduction of a manual signature that is included in any attachment. From Chris.Delnooz at hydrix.com Thu Sep 12 17:32:40 2013 From: Chris.Delnooz at hydrix.com (Chris Delnooz) Date: Thu Sep 12 17:32:57 2013 Subject: [xsd-users] Can I influence the order of attribute serialization? Message-ID: <1ABD3AB5D5D0DC439E0C9617AC6DF683B9C294@ALLEXCH.alloratech.local> Hi all, I have a complex type with a number of attributes defined as the snippet below. However, if I look at the serialized code, it doesn't respect the order in which the attributes were specified: Is there a way to force the serializer code to respect the order in the XSD? Thanks! Chris Delnooz | Software Architect chris.delnooz@hydrix.com Hydrix: Our Expertise - Your Competitive Advantage www.hydrix.com | fax +61 3 8573 5289 | direct +61 3 8573 5248 From boris at codesynthesis.com Fri Sep 13 06:39:35 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Sep 13 06:41:11 2013 Subject: [xsd-users] Can I influence the order of attribute serialization? In-Reply-To: <1ABD3AB5D5D0DC439E0C9617AC6DF683B9C294@ALLEXCH.alloratech.local> References: <1ABD3AB5D5D0DC439E0C9617AC6DF683B9C294@ALLEXCH.alloratech.local> Message-ID: Hi Chris, Chris Delnooz writes: > However, if I look at the serialized code, it doesn't respect the > order in which the attributes were specified: XSD (i.e., the generated code) actually serializes them in the order specified in the schema. This is Xerces-C++ behvaior. Generally, in XML, the order of attributes is not significant and is not preserved. Xerces-C++, for example, stores them in a map (keyed to the attribute name; for easier lookup) and when it comes time to serialize, it simply writes them in that order, which is why you end up with an alphabetically sorted list. Do you need them in a specific order for aesthetic purposes or for some other reason (e.g., a non-conforming XML parser on the other end)? Boris From hargtholan at gmail.com Fri Sep 13 10:39:34 2013 From: hargtholan at gmail.com (Harg Tholan) Date: Fri Sep 13 10:39:41 2013 Subject: [xsd-users] [xsd] Polymorphism dynamic_cast returns 0. Message-ID: Hi, I started a re-factor in my project aiming to replace the "xs:choice polymorphism" with proper XML polymorphism (xsi:type), the dynamic casting fails to retrieve the actual type. I am using "--generate-polymorphic", and even specifying the base types with "--polymorphic-type". In section 5.4 of the manual it is mentioned this: " [...] as well as pass true as the last argument to the xml_schema::document's constructors.", but I do not know how to call such constructor. I am instantiating my objects this way: std::auto_ptr obj(xml::foo::Obj(argv[1],xml_schema::flags:: dont_validate)); then I perform the dynamic type checking like: if (xml::foo::ConcreteBar* c = dynamic_cast (&(* itr))) (where itr is an iterator of a sequence of base type elements). I inspected the generated code and looks fine (ConcreteBar inherits from public Bar). What am I doing wrong? Thanks. From boris at codesynthesis.com Fri Sep 13 10:56:33 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Sep 13 10:58:10 2013 Subject: [xsd-users] [xsd] Polymorphism dynamic_cast returns 0. In-Reply-To: References: Message-ID: Hi Harg, Harg Tholan writes: > In section 5.4 of the manual it is mentioned this: " [...] as well > as pass true as the last argument to the xml_schema::document's > constructors.", but I do not know how to call such constructor. That only applies to the C++/Parser mapping while you are using C++/Tree. > then I perform the dynamic type checking like: > > if (xml::foo::ConcreteBar* c = dynamic_cast (&(* > itr))) > > (where itr is an iterator of a sequence of base type elements). > > I inspected the generated code and looks fine (ConcreteBar inherits from > public Bar). What am I doing wrong? Hm, if Bar is made polymorphic (with --polymorphic-type) and the actual type in XML is of the derived type (i.e., it either uses a substitution group or xsi:type), then everything should work fine. You don't seem to be slicing the object. You may want to print the name of the dynamic type and see what it reveals: cerr << typeid (*itr).name () << endl; If that doesn't help, can you show the relevant XML fragment? Boris From Chris.Delnooz at hydrix.com Sun Sep 15 17:32:33 2013 From: Chris.Delnooz at hydrix.com (Chris Delnooz) Date: Sun Sep 15 17:32:45 2013 Subject: [xsd-users] Can I influence the order of attribute serialization? In-Reply-To: References: <1ABD3AB5D5D0DC439E0C9617AC6DF683B9C294@ALLEXCH.alloratech.local> Message-ID: <1ABD3AB5D5D0DC439E0C9617AC6DF683B9C30E@ALLEXCH.alloratech.local> Hi Boris, Thanks, that explains what I see happening. I wanted it in a specific order to avoid discussion later on ;) But I'll manage with the way it works now. No worries. Thanks! Chris -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Friday, 13 September 2013 8:40 PM To: Chris Delnooz Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] Can I influence the order of attribute serialization? Hi Chris, Chris Delnooz writes: > However, if I look at the serialized code, it doesn't respect the > order in which the attributes were specified: XSD (i.e., the generated code) actually serializes them in the order specified in the schema. This is Xerces-C++ behvaior. Generally, in XML, the order of attributes is not significant and is not preserved. Xerces-C++, for example, stores them in a map (keyed to the attribute name; for easier lookup) and when it comes time to serialize, it simply writes them in that order, which is why you end up with an alphabetically sorted list. Do you need them in a specific order for aesthetic purposes or for some other reason (e.g., a non-conforming XML parser on the other end)? Boris From hargtholan at gmail.com Mon Sep 16 02:49:49 2013 From: hargtholan at gmail.com (Harg Tholan) Date: Mon Sep 16 02:49:55 2013 Subject: [xsd-users] [xsd] Polymorphism dynamic_cast returns 0. In-Reply-To: References: Message-ID: Hi, Thanks for your help, typeid (*itr).name() tells that the type is "Bar", in my XML document I have instances of "ConcreteBar". Thanks. 2013/9/13 Boris Kolpackov > Hi Harg, > > Harg Tholan writes: > > > In section 5.4 of the manual it is mentioned this: " [...] as well > > as pass true as the last argument to the xml_schema::document's > > constructors.", but I do not know how to call such constructor. > > That only applies to the C++/Parser mapping while you are using > C++/Tree. > > > then I perform the dynamic type checking like: > > > > if (xml::foo::ConcreteBar* c = dynamic_cast (&(* > > itr))) > > > > (where itr is an iterator of a sequence of base type elements). > > > > I inspected the generated code and looks fine (ConcreteBar inherits from > > public Bar). What am I doing wrong? > > Hm, if Bar is made polymorphic (with --polymorphic-type) and the actual > type in XML is of the derived type (i.e., it either uses a substitution > group or xsi:type), then everything should work fine. You don't seem > to be slicing the object. > > You may want to print the name of the dynamic type and see what it > reveals: > > cerr << typeid (*itr).name () << endl; > > If that doesn't help, can you show the relevant XML fragment? > > Boris > From boris at codesynthesis.com Mon Sep 16 04:27:21 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Sep 16 04:28:56 2013 Subject: [xsd-users] [xsd] Polymorphism dynamic_cast returns 0. In-Reply-To: References: Message-ID: Hi Harg, Harg Tholan writes: > [...] typeid (*itr).name() tells that the type is "Bar", in my XML > document I have instances of "ConcreteBar". What does the relevant XML fragment looks like? Boris From ellinger.klaus.ext at siemens.com Mon Sep 23 09:54:57 2013 From: ellinger.klaus.ext at siemens.com (Ellinger (EXT), Klaus) Date: Mon Sep 23 09:55:09 2013 Subject: [xsd-users] Change Id and all IdRef's Message-ID: <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C7F64@DEKOMMBX001B.net.plm.eds.com> Hello Boris, I have a requirement and I am not sure how to solve it, hopefully you can give me an hint if and how it's possible. I have an xsd schema defined with ID and IDREF types. In some cases I have to replace some Id's after processing so I need to update all IDREF's too to get a valid XML file out. I studied the code of ID and IDREF as far I could and mentioned that both classes are subtypes of "xsd::string" and the id value will not be updated on change. Do you see a solution to update all IDREFS if an ID changes? Best regards Klaus ----------------- Siemens Industry Software GmbH; Sitz der Gesellschaft: Wolfgang-Pauli-Strasse 2, A-4020 Linz, ?sterreich Firmenbuchnummer: FN 214676 a; Firmenbuchgericht: Handelsgericht Linz From boris at codesynthesis.com Tue Sep 24 05:49:01 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Sep 24 05:51:21 2013 Subject: [xsd-users] Change Id and all IdRef's In-Reply-To: <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C7F64@DEKOMMBX001B.net.plm.eds.com> References: <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C7F64@DEKOMMBX001B.net.plm.eds.com> Message-ID: Hi Klaus, Ellinger (EXT), Klaus writes: > I have a requirement and I am not sure how to solve it, hopefully you can > give me an hint if and how it's possible. I have an xsd schema defined with > ID and IDREF types. In some cases I have to replace some Id's after > processing so I need to update all IDREF's too to get a valid XML file > out. I studied the code of ID and IDREF as far I could and mentioned that > both classes are subtypes of "xsd::string" and the id value will not be > updated on change. Do you see a solution to update all IDREFS if an ID > changes? Conceptually, changing ID is a bad idea exactly for this reason -- all the places that assumed the ID is immutable have to now be updated. So instead of changing the ID, consider removing this requirements at the "allocation logic" level. For example, maybe you can replace a "full" element that has the ID that you need to change with a special "forwarding" element that specifies both the old ID and the ID of the new "full" element. If you still need to change the ID and somehow update all the IDREFs that point to it, I am afraid there is no easy way. The best I could think of would be to customize both the ID and IDREF types (see the custom/calendar example for how to customize a built-in type) so that IDREF instances register on the IDs that they point to and ID instances contain a set of all the IDREFs that point to them. You will also have to deal with forward references (i.e., referenced ID hasn't been seen yet) so maybe it is actually better to have one map in the root of the object model (that's how the IDREF-to-ID resolution works now). I am sure this can be done, it is just not going to be easy. Boris From ellinger.klaus.ext at siemens.com Tue Sep 24 10:46:08 2013 From: ellinger.klaus.ext at siemens.com (Ellinger (EXT), Klaus) Date: Tue Sep 24 10:46:20 2013 Subject: [xsd-users] Change Id and all IdRef's In-Reply-To: References: <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C7F64@DEKOMMBX001B.net.plm.eds.com> Message-ID: <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C83E9@DEKOMMBX001B.net.plm.eds.com> Hello Boris, Thx for the response. I tried to customize the standard IDREF by using following command line parameter: --custom-type IDREF=myidref In the generated schema there is also class definition for myidref, the problem is that in the generated code the default type is used "::xsd::cxx::tree::idref<....>". Can I replace the ootb type by regular expressions? Best regards Klaus -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Dienstag, 24. September 2013 11:49 To: Ellinger (EXT), Klaus Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] Change Id and all IdRef's Hi Klaus, Ellinger (EXT), Klaus writes: > I have a requirement and I am not sure how to solve it, hopefully you > can give me an hint if and how it's possible. I have an xsd schema > defined with ID and IDREF types. In some cases I have to replace some > Id's after processing so I need to update all IDREF's too to get a > valid XML file out. I studied the code of ID and IDREF as far I could > and mentioned that both classes are subtypes of "xsd::string" and the > id value will not be updated on change. Do you see a solution to > update all IDREFS if an ID changes? Conceptually, changing ID is a bad idea exactly for this reason -- all the places that assumed the ID is immutable have to now be updated. So instead of changing the ID, consider removing this requirements at the "allocation logic" level. For example, maybe you can replace a "full" element that has the ID that you need to change with a special "forwarding" element that specifies both the old ID and the ID of the new "full" element. If you still need to change the ID and somehow update all the IDREFs that point to it, I am afraid there is no easy way. The best I could think of would be to customize both the ID and IDREF types (see the custom/calendar example for how to customize a built-in type) so that IDREF instances register on the IDs that they point to and ID instances contain a set of all the IDREFs that point to them. You will also have to deal with forward references (i.e., referenced ID hasn't been seen yet) so maybe it is actually better to have one map in the root of the object model (that's how the IDREF-to-ID resolution works now). I am sure this can be done, it is just not going to be easy. Boris ----------------- Siemens Industry Software GmbH; Sitz der Gesellschaft: Wolfgang-Pauli-Strasse 2, A-4020 Linz, ?sterreich Firmenbuchnummer: FN 214676 a; Firmenbuchgericht: Handelsgericht Linz From boris at codesynthesis.com Wed Sep 25 05:42:27 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Sep 25 05:44:45 2013 Subject: [xsd-users] Change Id and all IdRef's In-Reply-To: <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C83E9@DEKOMMBX001B.net.plm.eds.com> References: <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C7F64@DEKOMMBX001B.net.plm.eds.com> <8616BD3D6AF1C8419FB1F9D1DB58416C2A5C83E9@DEKOMMBX001B.net.plm.eds.com> Message-ID: Hi Klaus, Ellinger (EXT), Klaus writes: > Thx for the response. I tried to customize the standard IDREF by > using following command line parameter: > > --custom-type IDREF=myidref > > In the generated schema there is also class definition for myidref, > the problem is that in the generated code the default type is used > "::xsd::cxx::tree::idref<....>". Can I replace the ootb type by > regular expressions? I don't understand what you are trying to say above. Generally, there are a couple of special steps required when customizing the built-in types. Please study the example I mentioned in my previous email as well as the C++/Tree Mapping Customization Guide: http://wiki.codesynthesis.com/Tree/Customization_guide Boris From ashish at ashishsinghal.com Thu Sep 26 04:24:48 2013 From: ashish at ashishsinghal.com (Ashish Singhal) Date: Thu Sep 26 04:31:21 2013 Subject: [xsd-users] Schema caching example: enabe schema caching automatically Message-ID: Are there any hooks for configuring the xerces-c parser used for loading xml to cache the schema automatically? I had a look at the schema caching example supplied with xsd and it works, but it ends up being a 2 stage process: 1) load the xml schema using xerces-c (with the caching parser) 2) construct the xsd generated object. I'd like to skip #1 and have it done automatically by xsd generated code. The 2 stage process is inconvenient, as I have a significant amount of code that loads xml files using the generated constructors. It would be difficult to change everything to the two stage loading process. From boris at codesynthesis.com Thu Sep 26 06:09:04 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Sep 26 06:11:28 2013 Subject: [xsd-users] Schema caching example: enabe schema caching automatically In-Reply-To: References: Message-ID: Hi Ashish, Ashish Singhal writes: > Are there any hooks for configuring the xerces-c parser used for loading > xml to cache the schema automatically? > > I had a look at the schema caching example supplied with xsd and it works, > but it ends up being a 2 stage process: > > 1) load the xml schema using xerces-c (with the caching parser) > 2) construct the xsd generated object. > > I'd like to skip #1 and have it done automatically by xsd generated code. Normally, the idea behind schema caching is that you want to do it once and then reuse the grammar to parse multiple documents. And to achieve this, you need to reuse the XML parser. On the other hand, the generated parsing functions create a new XML parser for every invocation, so even if there were a way to configure the parser used, it would be destroyed at the end of the call. That's why to do caching you need to have your own XML-to-DOM stage. This way you can make sure the same parser is used, in some application-specific way. > The 2 stage process is inconvenient, as I have a significant amount of code > that loads xml files using the generated constructors. It would be > difficult to change everything to the two stage loading process. You can always wrap the generated parsing functions (I assume that's what you mean by "generated constructors") and hide all the schema caching. You will need to make sure that they all use a single parser in some way (e.g., a global parser for a single-threaded application and maybe TLS for multi-threaded). You could probably even make this wrapper a function template. Note also that it is possible to tell Xerces-C++ to load and cache the schemas automatically, as it parses XML documents that reference them instead of pre-loading them manually at the beginning. Boris From ashish at ashishsinghal.com Thu Sep 26 06:30:53 2013 From: ashish at ashishsinghal.com (Ashish Singhal) Date: Thu Sep 26 06:58:24 2013 Subject: [xsd-users] Schema caching example: enabe schema caching automatically In-Reply-To: References: Message-ID: >You can always wrap the generated parsing functions (I assume that's >what you mean by "generated constructors") and hide all the schema >caching My concern is with having to change every invocation to use the wrapper - my application has hundreds of invocations using the non-cached parser. Tracking them all down will be difficult. Is there an approach that can help avoid this? On Thu, Sep 26, 2013 at 11:09 AM, Boris Kolpackov wrote: > Hi Ashish, > > Ashish Singhal writes: > > > Are there any hooks for configuring the xerces-c parser used for loading > > xml to cache the schema automatically? > > > > I had a look at the schema caching example supplied with xsd and it > works, > > but it ends up being a 2 stage process: > > > > 1) load the xml schema using xerces-c (with the caching parser) > > 2) construct the xsd generated object. > > > > I'd like to skip #1 and have it done automatically by xsd generated code. > > Normally, the idea behind schema caching is that you want to do it once > and then reuse the grammar to parse multiple documents. And to achieve > this, you need to reuse the XML parser. On the other hand, the generated > parsing functions create a new XML parser for every invocation, so even > if there were a way to configure the parser used, it would be destroyed > at the end of the call. That's why to do caching you need to have your > own XML-to-DOM stage. This way you can make sure the same parser is used, > in some application-specific way. > > > > The 2 stage process is inconvenient, as I have a significant amount of > code > > that loads xml files using the generated constructors. It would be > > difficult to change everything to the two stage loading process. > > You can always wrap the generated parsing functions (I assume that's > what you mean by "generated constructors") and hide all the schema > caching. You will need to make sure that they all use a single > parser in some way (e.g., a global parser for a single-threaded > application and maybe TLS for multi-threaded). You could probably > even make this wrapper a function template. > > Note also that it is possible to tell Xerces-C++ to load and cache > the schemas automatically, as it parses XML documents that reference > them instead of pre-loading them manually at the beginning. > > Boris > From boris at codesynthesis.com Thu Sep 26 07:02:00 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Sep 26 07:04:24 2013 Subject: [xsd-users] Schema caching example: enabe schema caching automatically In-Reply-To: References: Message-ID: Hi Ashish, Ashish Singhal writes: > My concern is with having to change every invocation to use the wrapper - > my application has hundreds of invocations using the non-cached parser. > Tracking them all down will be difficult. Is there an approach that can > help avoid this? Hm. How many different parsing functions (i.e., root elements) do you have? If not too many, then you could suppress their generation (with, for example, --root-element-none) and then provide your own implementations (which do caching) in their place. If you look at the generated overloads that take DOMDocument, they are pretty simple. Boris From ashish at ashishsinghal.com Thu Sep 26 07:25:59 2013 From: ashish at ashishsinghal.com (Ashish Singhal) Date: Thu Sep 26 09:07:40 2013 Subject: [xsd-users] Schema caching example: enabe schema caching automatically In-Reply-To: References: Message-ID: Unfortunately, there's hundreds of root elements as well. On Thu, Sep 26, 2013 at 12:02 PM, Boris Kolpackov wrote: > Hi Ashish, > > Ashish Singhal writes: > > > My concern is with having to change every invocation to use the wrapper - > > my application has hundreds of invocations using the non-cached parser. > > Tracking them all down will be difficult. Is there an approach that can > > help avoid this? > > Hm. How many different parsing functions (i.e., root elements) do you > have? If not too many, then you could suppress their generation (with, > for example, --root-element-none) and then provide your own > implementations (which do caching) in their place. If you look at the > generated overloads that take DOMDocument, they are pretty simple. > > Boris > From boris at codesynthesis.com Thu Sep 26 09:22:00 2013 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Sep 26 09:24:23 2013 Subject: [xsd-users] Schema caching example: enabe schema caching automatically In-Reply-To: References: Message-ID: Hi Ashish, Ashish Singhal writes: > Unfortunately, there's hundreds of root elements as well. You may then want to check out the element type feature (see the 'messaging' example). You will still need to change your code that calls the parsing functions, but at least you will be able to handle all the root elements with a single function template and the C++ compiler will pin-point all the places that need changing (since the parsing functions won't be there). Boris