From sutambe at dre.vanderbilt.edu Tue Dec 1 16:52:40 2009 From: sutambe at dre.vanderbilt.edu (Sumant Tambe) Date: Tue Dec 1 16:52:24 2009 Subject: [xsd-users] type inheritance/substitution and generated class interface Message-ID: <4B159028.2060006@dre.vanderbilt.edu> Hi, I've some follow-up questions on a xsd-users thread that is over 4 years old! Here's a URL: http://www.codesynthesis.com/pipermail/xsd-users/2005-September/000026.html 1. Once the XML is parsed and and in-memory object model is created, how do I downcast from base to derived type? Specifically from the example, how do I know that a Person is in fact a Superman and get a Superman type of object from the Person object. I tried dynamic_cast thinking that person object reference might be polymorphic, but it does not seem to work. 2. Does substitutionGroup have any effect on the generated class interface? Again from the example, if Superman is part of the Person substitution group, is it possible (or does it makes sense) to have a separate member function called superman that returns only supermen? If not, how do I casting in this case? Thanks, Sumant. From boris at codesynthesis.com Wed Dec 2 08:31:57 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 2 08:25:12 2009 Subject: [xsd-users] type inheritance/substitution and generated class interface In-Reply-To: <4B159028.2060006@dre.vanderbilt.edu> References: <4B159028.2060006@dre.vanderbilt.edu> Message-ID: Hi Sumant, Sumant Tambe writes: > 1. Once the XML is parsed and and in-memory object model is created, how > do I downcast from base to derived type? Specifically from the example, > how do I know that a Person is in fact a Superman and get a Superman > type of object from the Person object. I tried dynamic_cast thinking > that person object reference might be polymorphic, but it does not seem > to work. The two most common reasons why this does not work are: 1. You haven't compiled your schemas with the --generate-polymorphic option. 2. You have made a "sliced" copy of the object model node. When dealing with polymorphic object models you should use references or make complete copies using the _clone() function. For more information see Section 2.11, "Mapping for xsi:type and Substitution Groups" in the C++/Tree Mapping User Manual: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.11 As well as the polymorphism example in th examples/cxx/tree/ directory. > 2. Does substitutionGroup have any effect on the generated class > interface? No, substitution groups are handled automatically by the generated code. Unless you use DOM, there is way to tell whether xsi:type or the substitution groups mechanism was used to provide the dynamic type. Boris From sutambe at dre.vanderbilt.edu Wed Dec 2 22:18:12 2009 From: sutambe at dre.vanderbilt.edu (Sumant Tambe) Date: Wed Dec 2 22:18:10 2009 Subject: [xsd-users] type inheritance/substitution and generated class interface In-Reply-To: References: <4B159028.2060006@dre.vanderbilt.edu> Message-ID: <4B172DF4.3030405@dre.vanderbilt.edu> Hi Boris, > 1. You haven't compiled your schemas with the --generate-polymorphic > option. This took care of it. > As well as the polymorphism example in th examples/cxx/tree/ directory. This example is good. Thanks, Sumant. From bschindler at inf.ethz.ch Wed Dec 9 04:15:28 2009 From: bschindler at inf.ethz.ch (Benjamin Schindler) Date: Wed Dec 9 04:59:24 2009 Subject: [xsd-users] gcc -fvisibility Message-ID: <4B1F6AB0.9020900@inf.ethz.ch> Hi I work on a project that uses xsd to compile the xsd schemas. I now had the idea to make -fvisibility=hidden default for the project on linux but that does not work because the maps don't seem to be exported the same way they are on windows. I use the --import-maps on all of my shared object files (dll's on windows). On windows, this works just fine, on linux it works if I leave the default visibility, but with visibility=hidden, I get exceptions like: no type information available for type 'SynthSettings_t' Is this a bug in xsd? Thanks Benjamin From boris at codesynthesis.com Wed Dec 9 08:14:07 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 9 08:07:06 2009 Subject: [xsd-users] gcc -fvisibility In-Reply-To: <4B1F6AB0.9020900@inf.ethz.ch> References: <4B1F6AB0.9020900@inf.ethz.ch> Message-ID: Hi Benjamin, Benjamin Schindler writes: > I use the --import-maps on all of my shared object files (dll's on > windows). On windows, this works just fine, on linux it works if I leave > the default visibility, but with visibility=hidden, I get exceptions like: > > no type information available for type 'SynthSettings_t' > > Is this a bug in xsd? Currently the --import/export-maps options only support VC++ and use the template instantiation export syntax (which is quite peculiar) directly. I played with GCC's __attribute__ ((visibility("default"))) syntax in the same context and it seems to work ok. So I went ahead and added it to the code generator. Here is a pre-release binary with this functionality: http://www.codesynthesis.com/~boris/tmp/xsd-3.3.0.a8-i686-linux-gnu.tar.bz2 Can you try it on your project and let me know if everything works as expected? If it works, then I will commit this for the next release of XSD. Thanks, Boris From bschindler at inf.ethz.ch Thu Dec 10 06:20:51 2009 From: bschindler at inf.ethz.ch (Benjamin Schindler) Date: Thu Dec 10 06:21:52 2009 Subject: [xsd-users] gcc -fvisibility In-Reply-To: References: <4B1F6AB0.9020900@inf.ethz.ch> Message-ID: <4B20D993.70905@inf.ethz.ch> Hi Boris It's a bit difficult to test here as the system is a bit busted atm. But it seemed that the change worked. I cannot say for 100%, but it seemed to work Thank you a lot! Benjamin On 12/09/2009 02:14 PM, Boris Kolpackov wrote: > Hi Benjamin, > > Benjamin Schindler writes: > > >> I use the --import-maps on all of my shared object files (dll's on >> windows). On windows, this works just fine, on linux it works if I leave >> the default visibility, but with visibility=hidden, I get exceptions like: >> >> no type information available for type 'SynthSettings_t' >> >> Is this a bug in xsd? >> > Currently the --import/export-maps options only support VC++ and use the > template instantiation export syntax (which is quite peculiar) directly. > > I played with GCC's __attribute__ ((visibility("default"))) syntax in the > same context and it seems to work ok. So I went ahead and added it to the > code generator. Here is a pre-release binary with this functionality: > > http://www.codesynthesis.com/~boris/tmp/xsd-3.3.0.a8-i686-linux-gnu.tar.bz2 > > Can you try it on your project and let me know if everything works as > expected? If it works, then I will commit this for the next release of > XSD. > > Thanks, > Boris > From bschindler at inf.ethz.ch Mon Dec 14 05:34:12 2009 From: bschindler at inf.ethz.ch (Benjamin Schindler) Date: Mon Dec 14 05:35:37 2009 Subject: [xsd-users] xsd include path Message-ID: <4B2614A4.6020609@inf.ethz.ch> Hi I'm having big trouble with our large projects: I cannot guarantee in which folder the program is called due to operating system / build system differences. The program is a server and receives an xml stream which it validates against some xsd's. Is there some way to set a root path against which xsd's are validated? Otherwise, locating xsd's is a very difficult job... Cheers Benjamin From boris at codesynthesis.com Mon Dec 14 06:10:35 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 14 06:03:30 2009 Subject: [xsd-users] xsd include path In-Reply-To: <4B2614A4.6020609@inf.ethz.ch> References: <4B2614A4.6020609@inf.ethz.ch> Message-ID: Hi Benjamin, Benjamin Schindler writes: > I'm having big trouble with our large projects: I cannot guarantee in > which folder the program is called due to operating system / build > system differences. The program is a server and receives an xml stream > which it validates against some xsd's. Is there some way to set a root > path against which xsd's are validated? Otherwise, locating xsd's is a > very difficult job... The best way to resolve this is to pre-load the schemas as shown in the 'caching' example in the examples/cxx/tree/ directory. This way you can specify absolute paths to the schema files. The added advantage of this approach is that you can re-use the schemas for validating more than one document. There is also a way to pre-compile the schema and embed them directly into the application. For more information on how to do this see the 'embedded' example which can get here: http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-embedded.tar.gz http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-embedded.zip Boris From bschindler at inf.ethz.ch Mon Dec 14 06:57:56 2009 From: bschindler at inf.ethz.ch (Benjamin Schindler) Date: Mon Dec 14 06:59:00 2009 Subject: [xsd-users] xsd include path In-Reply-To: References: <4B2614A4.6020609@inf.ethz.ch> Message-ID: <4B262844.807@inf.ethz.ch> Hi Thanks for the quick reply! On 12/14/2009 12:10 PM, Boris Kolpackov wrote: > Hi Benjamin, > > Benjamin Schindler writes: > > >> I'm having big trouble with our large projects: I cannot guarantee in >> which folder the program is called due to operating system / build >> system differences. The program is a server and receives an xml stream >> which it validates against some xsd's. Is there some way to set a root >> path against which xsd's are validated? Otherwise, locating xsd's is a >> very difficult job... >> > The best way to resolve this is to pre-load the schemas as shown in the > 'caching' example in the examples/cxx/tree/ directory. This way you can > specify absolute paths to the schema files. The added advantage of this > approach is that you can re-use the schemas for validating more than one > document. > I have looked at this example - but I'm a bit unsure about the semantics. What is the key for the cache-lookup? The path, the filename? What happens if two files have the same name? > There is also a way to pre-compile the schema and embed them directly into > the application. For more information on how to do this see the 'embedded' > example which can get here: > Thanks for the hint. I'm not sure whether that would work here as the xsd's are modified (in form of a temporary file) at run-time when plugins are loaded, so I cannot really compile schemas into the application or can I modify the binary representations at run-time? (i.e. add includes which are themselves then in form of a binary representation)? Thanks! Benjamin > http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-embedded.tar.gz > http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-embedded.zip > > Boris > From boris at codesynthesis.com Mon Dec 14 08:49:32 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 14 08:42:31 2009 Subject: [xsd-users] xsd include path In-Reply-To: <4B262844.807@inf.ethz.ch> References: <4B2614A4.6020609@inf.ethz.ch> <4B262844.807@inf.ethz.ch> Message-ID: Hi Benjamin, Benjamin Schindler writes: > I have looked at this example - but I'm a bit unsure about the > semantics. What is the key for the cache-lookup? The path, the filename? > What happens if two files have the same name? In the current versions of Xerces-C++ the key is the target namespace which means if you have more than one schema with the same namespace, you need to load the "root" schema which includes all the others. This is pretty much the same requirement as with the schemaLocation attributes. [For the next version of Xerces-C++ (3.1.0) I have done some work to allow loading multiple (different) schemas with the same namespace.] > Thanks for the hint. I'm not sure whether that would work here as the > xsd's are modified (in form of a temporary file) at run-time when > plugins are loaded, so I cannot really compile schemas into the > application or can I modify the binary representations at run-time? > (i.e. add includes which are themselves then in form of a binary > representation)? No, that is not possible. You will only be able to re-generate the complete binary representation. Which, I guess, won't be very useful in your case. Boris From Stephen.James at genband.com Tue Dec 15 17:45:15 2009 From: Stephen.James at genband.com (Stephen James) Date: Wed Dec 16 04:41:00 2009 Subject: [xsd-users] xml_schema::flags::no_xml_declaration leaves blank line In-Reply-To: References: <21F3A5EA2F1A8047A6EA370227C942B202C04A2A@gbplamail.genband.com> <21F3A5EA2F1A8047A6EA370227C942B202C04ADD@gbplamail.genband.com> <21F3A5EA2F1A8047A6EA370227C942B202C5E382@gbplamail.genband.com> Message-ID: <21F3A5EA2F1A8047A6EA370227C942B203070D69@gbplamail.genband.com> I am serializing my xml with: acbtcap(ss, out, map, "UTF-8", xml_schema::flags::no_xml_declaration); and instead of omitting the line it just omits the contents. I am still left with the blank line (\n). Also, how can I eliminate the xmlns: and xsi: contents below (bandwidth limited transport. From boris at codesynthesis.com Wed Dec 16 06:36:02 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Dec 16 06:28:52 2009 Subject: [xsd-users] Re: xml_schema::flags::no_xml_declaration leaves blank line In-Reply-To: <21F3A5EA2F1A8047A6EA370227C942B203070D69@gbplamail.genband.com> References: <21F3A5EA2F1A8047A6EA370227C942B202C04A2A@gbplamail.genband.com> <21F3A5EA2F1A8047A6EA370227C942B202C04ADD@gbplamail.genband.com> <21F3A5EA2F1A8047A6EA370227C942B202C5E382@gbplamail.genband.com> <21F3A5EA2F1A8047A6EA370227C942B203070D69@gbplamail.genband.com> Message-ID: Hi Stephen, Stephen James writes: > I am serializing my xml with: > > acbtcap(ss, out, map, "UTF-8", xml_schema::flags::no_xml_declaration); > > and instead of omitting the line it just omits the contents. > I am still left with the blank line (\n). This appears to be a bug in the Xerces-C++ pretty-printer. I have filed a report: https://issues.apache.org/jira/browse/XERCESC-1902 Xerces-C++ 3.1.0 is already in the release candidate stage so unfortunately the fix will have to wait until the release after it. The two possible workarounds are: 1. Disable pretty-printing. 2. Remove the leading newline from the resulting XML, for example: ostringstream ss; acbtcap(ss, out, map, "UTF-8", xml_schema::flags::no_xml_declaration); string s; const string& tmp (ss.str ()); if (!tmp.empty () && tmp[0] == '\n') s.assign (tmp, 1, tmp.size () - 1); else s = tmp; Or, if you need a C string (for example, to write it to a socket), then you can avoid copying: const string& tmp (ss.str ()); const char* s (tmp.c_str ()); if (!tmp.empty () && tmp[0] == '\n') s++; > Also, how can I eliminate the xmlns: and xsi: contents below (bandwidth > limited transport. > > xsi:noNamespaceSchemaLocation="acbtcap.xsd"/> You have something like this in your code: map[""].schema = "acbtcap.xsd"; Simply remove this like. Boris From michielsoede at hotmail.com Thu Dec 17 08:52:53 2009 From: michielsoede at hotmail.com (Michiel Soede) Date: Thu Dec 17 08:53:00 2009 Subject: [xsd-users] stream (from file) to base64binary Message-ID: Hi xsd users, I'm trying to directly read from a std::ifstream into a base64 binary. I saw in the documentation that there is a xsd::cxx::tree::base64_binary template class with a constructor with an istream as input. But I got no clue how to use this, and can't find any example. Does anybody have an example to use this? Or even better, directly from a file stream? best regards, Michiel _________________________________________________________________ Your E-mail and More On-the-Go. Get Windows Live Hotmail Free. http://clk.atdmt.com/GBL/go/171222985/direct/01/ From boris at codesynthesis.com Thu Dec 17 09:20:38 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Dec 17 09:13:25 2009 Subject: [xsd-users] stream (from file) to base64binary In-Reply-To: References: Message-ID: Hi Michiel, Michiel Soede writes: > I'm trying to directly read from a std::ifstream into a base64 binary. Is the data in the file base64-encoded or binary? > I saw in the documentation that there is a > > xsd::cxx::tree::base64_binary template class with a constructor with > an istream as input. That's a different kind of stream. This constructor is used to load the base64_binary object from a data representation stream (XDR, CDR, etc.), not from std::istream. Boris