From boris at codesynthesis.com Thu Oct 1 11:17:20 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] xs:choice representation in C++ In-Reply-To: References: Message-ID: Hi Leonid, Gershanovich, Leonid writes: > When I said that interface is not clear, what I meant is that by > looking at accessor signature developer might expect: > - exception for const reference accessor, when choice_arm points to > another variant arm. > - and either exception or actually changing variant arm when non > const reference accessor is used, after all following two statement > semantically almost equivalent: > > Obj.stringEl(newVal); > Obj.stringEl() = newVal; I agree, for some use-cases this might be the preferred behavior. However, in my experience, mobile/embedded developers prefer fast, small, and dangerous to big, slow, and safe ;-) > Also, how choice arm is initialized in default ctor? It is in a special, "unset" state. > And boost::get() does not need to throw exception, as it returns const > pointer, thus it can return NULL when uninitialized arm is requested. I don't see much difference, safety-wise, between forgetting to check the arm and forgetting to make sure the returned pointer is not 0. Dereferencing a NULL pointer also results in undefined behavior. > Does this mean that "full-blown validation" in XSD/e is equivalent to > Xerces validation? Currently XSD/e does not support some of the less commonly used constructs. For more information see Appendix A, "Supported XML Schema Constructs" in the Embedded C++/Parser Mapping Getting Started Guide: http://www.codesynthesis.com/projects/xsde/documentation/cxx/parser/guide/#A > As right now I rely on Xerces to do validation, including xs:unique, > xs:key constraints. Those are not yet supported by XSD/e. > If answer to previous question is yes, then my next question would be - > why keep Xerces support? While validation in the generated code has its advantages, having it at the "lower level" makes the architecture much more flexible. Some of the very powerful mechanisms in C++/Tree, such as type customization, typeless content handling, and XPath execution are possible because of the use of the DOM representation and validation in the underlying XML parser. > > It is also a partial solution that can only address some choice use- > > cases, as I showed in my previous email. > > I do not exactly understand that do you mean? It seems to me that all > use cases from you previous emails can be covered by boost::variant + > overloaded accessors. Am I missing something? I was referring to the fact that you will still have to generate nested classes for more complex situations. And if we are going that route, we might as well do it for simple cases and provide an interface that is more convenient to use. This is what we did in XSD/e. This is, of course, assuming you agree with me that the C++/Hybrid mapping for choice is better than boost::variant ;-). It seems to me that the only advantage boost::variant's safe (but heavy-weight) interface has is that the compiler will complain if you forget to handle some arms. Some compilers (e.g., g++) warn you if you don't handle all enum values in a switch statement. So if you use switch to handle the values, then you can get a similar level of safety. Also, your statement about overloaded accessors got me thinking about a situation like this: That is, you have two choice arms with the same type. I don't think boost::variant will be able to handle this (i.e., which arm will boost::get() return?) Boris From sun.rise.ma at gmail.com Fri Oct 2 07:06:16 2009 From: sun.rise.ma at gmail.com (sun-rise) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] About using XPath Query Message-ID: <67b106680910020406u65ea2b0cs452087f6710e5ff6@mail.gmail.com> Hi, I have questions about a XPath query on XSD. 1. I refers to the XPath example in the example/cxx/tree/xpath of XSD distribution. The sample uses the DOMDocument object parsed from a XML file. I want to execute a XPath query for C++/Tree object model that created from scratch. Can use an C++/Tree object model created from scratch be used instead of the DOMDocument parsed from a file? # Example code uses DOMImplementation object when prasing a XML file. # If I created C++/Tree object model from scratch (don't parse a file), how should be # used DOMImplementation? 2. Can I add a new element to XPath result of C++/Tree object model? Example ------- John Doe male 32 member ... ------- Evalate a following XPath expression for C++/Tree object. /employee/person[@id='001'] Then, add a new element to /employee/person[@id='001']. ------- John Doe male 32 member admin ... ------- Thanks. -- Yu From boris at codesynthesis.com Mon Oct 5 03:47:28 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] About using XPath Query In-Reply-To: <67b106680910020406u65ea2b0cs452087f6710e5ff6@mail.gmail.com> References: <67b106680910020406u65ea2b0cs452087f6710e5ff6@mail.gmail.com> Message-ID: Hi, sun-rise writes: > I want to execute a XPath query for C++/Tree object model that > created from scratch. This is not possible at the moment since XPath is executed on the underlying DOMDocument which can only be associated with the object model during parsing (more precisely, you could create corresponding DOM nodes and manually associate them with the object model nodes but this is very tedious so I wouldn't recommend it). The somewhat ugly work around would to serialize and re-parse the object model to get the DOM association. Also, we are working on a feature for the next release of XSD which will allow you to run XPath/XQuery queries natively on the object model. With this feature you will be able to do it on any object model. > 2. Can I add a new element to XPath result of C++/Tree object model? > > Example > ------- > > > John > Doe > male > 32 > member > > > > ... > > > ------- > > Evalate a following XPath expression for C++/Tree object. > /employee/person[@id='001'] > > Then, add a new element to /employee/person[@id='001']. > > ------- > > > John > Doe > male > 32 > member > admin > > > > ... > > > ------- Yes, you can do that. You can evaluate the expression as shown in the example and then get back from the DOM node to the corresponding object model node (person, in this case). Then you can use the standard object model API to add another role element. The only limitation of this approach is that when you add another role element, the underlying DOM document will not be automatically updated. This means that if you try to execute another XPath expression that need to examine this new data, it won't be able to find anything. This shortcoming will also be addressed by the native XPath feature. Boris From xsd at faultline.com Wed Oct 7 17:11:12 2009 From: xsd at faultline.com (Carl) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Using regular expressions Message-ID: <4ACD03F0.1080904@faultline.com> I am having problems with regular expressions. I am trying to parse the XSD files supplied by California to support efiling of payroll tax returns. There are several files that reference each other but also reuse some element names. These cause conflicts when generating the C++ code. I tried using regular expressions and got at least as far as generating all the C++ files. Now compiling these files generates errors of conflicting class names. So I'm not sure the regular expressions did what I thought. Here is an example of what I am trying to do: The files StateWH.xsd and StateUI.xsd both contain an element called AmendedReturnElect among many others. So after much trial and error I came up with this regular expression in the hopes that all classes in the StateWH file would have WH_ prepended to the names. --anonymous-regex ,.*StateWH.xsd .* StateWHType/.*,WH_$0, But I don't see any evidence of this in the StateWH.hxx file. Without this xsd would not generate the .cxx or .hxx files. It just complained about name conflicts so the regex did something but I don't know what. The way I read the regex I used is in any file matching *StateWH.xsd any namespace any element name starting with StateWHType add WH_ to the start of the name So what did I really do and how do I get this to actually change the class names with a few prepended characters so I avoid the conflicts? Thanks, Carl From boris at codesynthesis.com Thu Oct 8 12:48:33 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Using regular expressions In-Reply-To: <4ACD03F0.1080904@faultline.com> References: <4ACD03F0.1080904@faultline.com> Message-ID: Hi Carl, Carl writes: > Here is an example of what I am trying to do: > > The files StateWH.xsd and StateUI.xsd both contain an element called > AmendedReturnElect among many others. > So after much trial and error I came up with this regular expression > in the hopes that all classes in the StateWH file would have WH_ > prepended to the names. > > --anonymous-regex ,.*StateWH.xsd .* StateWHType/.*,WH_$0, Because the file name in the pattern is empty for the file that is being compiled, you will need to use this expressions: --anonymous-regex ,.* .* StateWHType/(.*),WH_$1, It will cover both cases: when StateWH.xsd is the file that is being compiled and when StateWH.xsd is imported/included from other schemas. BTW, you can use the --anonymous-regex-trace option to see what your expressions are applied to and whether they match. Useful for debugging. The above approach will require a separate expression for each schema file and can become a bit tedious. If you don't mind using a more "regular" naming scheme then you can cover all your schema files with one expression. For example, this regex: --anonymous-regex ',.* .* (.*)/(.*),$1_$2,' Will name all your anonymous types like StateWHType_AmendedReturnElect, StateUIType_AmendedReturnElect, etc. Let us know if this doesn't work you. Boris From christopher.fuhrman at etsmtl.ca Thu Oct 8 15:19:17 2009 From: christopher.fuhrman at etsmtl.ca (Christopher Fuhrman) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Using regular expressions In-Reply-To: References: <4ACD03F0.1080904@faultline.com> Message-ID: <955f8a1b0910081219t57ecdb7bu7478478d3645fb66@mail.gmail.com> Hi all, On Thu, Oct 8, 2009 at 12:48 PM, Boris Kolpackov wrote: > BTW, you can use the --anonymous-regex-trace option to see what your > expressions are applied to and whether they match. Useful for > debugging. > > The above approach will require a separate expression for each schema > file and can become a bit tedious. If you don't mind using a more > "regular" naming scheme then you can cover all your schema files with > one expression. For example, this regex: > > --anonymous-regex ',.* .* (.*)/(.*),$1_$2,' > > Will name all your anonymous types like StateWHType_AmendedReturnElect, > StateUIType_AmendedReturnElect, etc. > For regex testing, I recommend any of the many regex debugging tools that are available these days (some are even available in web pages or plug-ins to your favorite IDE). They save a lot of time since you can experiment with a reg-ex in one field, a sample text in another, and you see what would be matched/replaced, etc. before actually running it in the tool that requires the reg-ex. -- Cris From xsd at faultline.com Thu Oct 8 19:00:24 2009 From: xsd at faultline.com (Carl) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Using regular expressions In-Reply-To: References: <4ACD03F0.1080904@faultline.com> Message-ID: <4ACE6F08.7090006@faultline.com> On 10/08/2009 12:48 PM, Boris Kolpackov wrote: > > The above approach will require a separate expression for each schema > file and can become a bit tedious. If you don't mind using a more > "regular" naming scheme then you can cover all your schema files with > one expression. For example, this regex: > > --anonymous-regex ',.* .* (.*)/(.*),$1_$2,' > > Will name all your anonymous types like StateWHType_AmendedReturnElect, > StateUIType_AmendedReturnElect, etc. Thank you for that. It solved all the name conflict problems I was having. Carl From greg at permedia.ca Fri Oct 9 11:19:27 2009 From: greg at permedia.ca (Greg Carter) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Compiling to multiple DLLs, duplicate symbols problem Message-ID: I have a schema spread across about 20 xsd files. I have a number of custom types. Up until now I have been compiling all the generated/custom xml code as a static lib. I am now looking at breaking up the static lib into two shared libs. I have two DLL projects (windows for now). The first contains the 'base' XML code, the second uses the first. In Release mode the dlls build and execute fine. In debug mode when I build my second dll (which links to the first) I get duplicate link errors (error LNK2005). An example is: geocosmxmllibbasecpp.lib(geocosmxmllibbasecpp.dll) : error LNK2005: "public: virtual __thiscall xsd::cxx::tree::string >::~string >(void)" (??1?$string@DV?$simple_type@V_type@tree@cxx@xsd@@@tree@cxx@xsd@@@tree@cxx@xsd@@UAE@XZ) already defined in DerivativeSchema.obj here geocosmxmllibbasecpp.lib is the base DLL being link to, DerivativeSchema.obj is part of the DLL attempting to link. I've been all over the various link options and can't seem to find any solution. I have the projects setup so that a debug build of DLL 2 links to the .lib produced by the debug build of DLL 1. This is a sample of the XSD command line for a .xsd file in DLL 1: $(XSD)\bin\xsd cxx-tree --options-file "$(ProjectDir)xsdcompileoptionsbase.txt" --output-dir "$(InputDir)gencode\cpp" --custom-type OptIterationControlType=/OptIterationControlType_base --hxx-epilogue "#include \"Optimization_custom.hxx\"" "$(InputDir)OptimizationSchema.xsd" options file has --proprietary-license --generate-intellisense --generate-serialization --generate-ostream --export-maps --generate-polymorphic --export-symbol GEOCOSMXMLBASE_SYMBOL_DECL --hxx-prologue #include --extern-xml-schema XSDBaseXmlSchema.xsd The geocosmexportxmlbase.h has: #ifdef GEOCOSMXMLLIBBASECPP_EXPORTS #define GEOCOSMXMLBASE_SYMBOL_DECL __declspec(dllexport) #else #define GEOCOSMXMLBASE_SYMBOL_DECL __declspec(dllimport) #endif and GEOCOSMXMLLIBBASECPP_EXPORTS is defined for the build. Sample for the second DLL (note uses import-maps): $(XSD)\bin\xsd.exe cxx-tree --options-file "$(InputDir)xsdcompileoptions.txt" --output-dir "$(InputDir)gencode\cpp" "$(InputDir)BurialHistorySchema.xsd" --proprietary-license --generate-intellisense --generate-serialization --generate-ostream --generate-polymorphic --import-maps --export-symbol GEOCOSMXML_SYMBOL_DECL --hxx-prologue #include --extern-xml-schema XSDBaseXmlSchema.xsd and exportxml.h has: #ifdef GEOCOSMXML_EXPORTS #define GEOCOSMXML_SYMBOL_DECL __declspec(dllexport) #else #define GEOCOSMXML_SYMBOL_DECL __declspec(dllimport) #endif I'm using Visual Studio 2005. Any ideas why I'm getting the duplicate symbols when building the second DLL? Thanks Greg. From greg at permedia.ca Fri Oct 9 11:26:08 2009 From: greg at permedia.ca (Greg Carter) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Compiling to multiple DLLs, duplicate symbols problem In-Reply-To: References: Message-ID: Forgot to mention I'm running xsd-3.2.0-i686-windows Greg Carter wrote: > I'm using Visual Studio 2005. > Any ideas why I'm getting the duplicate symbols when building the > second DLL? > Thanks > Greg. > From boris at codesynthesis.com Fri Oct 9 11:52:34 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Compiling to multiple DLLs, duplicate symbols problem In-Reply-To: References: Message-ID: Hi Greg, Greg Carter writes: > In Release mode the dlls build and execute fine. In debug mode when I > build my second dll (which links to the first) I get duplicate link > errors (error LNK2005). An example is: > > geocosmxmllibbasecpp.lib(geocosmxmllibbasecpp.dll) : error LNK2005: > "public: virtual __thiscall xsd::cxx::tree::string xsd::cxx::tree::simple_type > >::~string xsd::cxx::tree::_type> >(void)" > (??1?$string@DV?$simple_type@V_type@tree@cxx@xsd@@@tree@cxx@xsd@@@tree@cxx@xsd@@UAE@XZ) > already defined in DerivativeSchema.obj > > [...] > > I'm using Visual Studio 2005. > Any ideas why I'm getting the duplicate symbols when building the second > DLL? Yes, I think I have seen this already. In the release build these functions are eliminated by the optimizer but in the debug build they are there and for some reason VC++ doesn't sort it out as it should (note that ~string() above is synthesized by the C++ compiler; the source code never actually defines one). The solution for this problem is to export symbols for the built-in types from the "base" DLL and import them in all dependant DLLs and executables. To automate this we added a new option, --export-xml-schema, for the next release of XSD. You can give it a try by downloading this pre-release binary: http://www.codesynthesis.com/~boris/tmp/xsd-3.3.0.a5-i686-windows.zip In your case, you will need to add --export-xml-schema --export-symbol GEOCOSMXMLBASE_SYMBOL_DECL when generating the code for the XML Schema namespace (i.e., "compiling" XSDBaseXmlSchema.xsd). Let me know if this works for you. Boris From xsd at faultline.com Thu Oct 8 19:42:56 2009 From: xsd at faultline.com (Carl) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Error in containers.hxx Message-ID: <4ACE7900.30402@faultline.com> I am getting errors when compiling a file. I *think* the errors have to do with not having an == operator for the xml_schema::type class. I have seen the manual on how to add functionality to that class so that is likely how to fix this. But not all of the classes derived from xml_schema::type are showing this error and I have an error reported about the == operator in the containers.hxx file. So I wanted to check if this is a known problem or some missing command line options before making changes to the built in type. The error reported from the containers.hxx file is: /usr/include/xsd/cxx/tree/containers.hxx:454: error: no match for ?operator==? in ?((const xsd::cxx::tree::optional*)a)->xsd::cxx::tree::optional::operator* [with T = xsd::cxx::tree::_type]() == ((const xsd::cxx::tree::optional*)b)->xsd::cxx::tree::optional::operator* [with T = xsd::cxx::tree::_type]()? Searching the list archives did not turn up this error. The .xsd files that caused this are attached. The StatePayment.xsd is the file generating the error and it is in a subdir from the other two files. The other two files are included but they each compile without error. The xsd command options used for all files are: # options for cxx-tree mode when running xsd --anonymous-regex %.* .* (.+/)*(.+)%$1_$2% #--anonymous-regex-trace --namespace-regex %.* http://www.irs.gov/(.+)%$1% #--namespace-regex-trace --generate-serialization --generate-ostream --generate-doxygen --generate-comparison --generate-forward --generate-inline Is this a problem with the include file, the xsd files or just a function I need to add to the type class? Thanks, Carl -------------- next part -------------- A non-text attachment was scrubbed... Name: efileTypes.xsd Type: text/xml Size: 70260 bytes Desc: not available Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20091008/59a3c1fd/efileTypes.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: efileStateTypes.xsd Type: text/xml Size: 29534 bytes Desc: not available Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20091008/59a3c1fd/efileStateTypes.bin -------------- next part -------------- A non-text attachment was scrubbed... Name: StatePayment.xsd Type: text/xml Size: 19220 bytes Desc: not available Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20091008/59a3c1fd/StatePayment.bin From boris at codesynthesis.com Fri Oct 9 13:08:00 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Error in containers.hxx In-Reply-To: <4ACE7900.30402@faultline.com> References: <4ACE7900.30402@faultline.com> Message-ID: Hi Carl, Carl writes: > I am getting errors when compiling a file. I *think* the errors have to > do with not having an == operator for the xml_schema::type class. Yes, I think you are right. To understand why xml_schema::type doesn't provide operator== here is some background on the problem. xml_schema::type is a mapping for xsd:anyType type. This type is special in that it can contain anything: any attributes, any elements, and any text in between them. This type is seldom used explicitly in schemas, except as an abstract base type when polymorphism is in use. However, one design aspect of XML Schema (unfortunate, IMO) is that if you forget to specify the type attribute for an element, by default it becomes xsd:anyType. So here is an example from your schema: Wire Transfer Indentifier I don't think the author(s) of this schema meant to use anyType and allow, say, something like this (which is legal, according to this schema): <... Massive XHTML document goes here ...> All they probably wanted was to allow a text string and xsd:string would have been a much better choice for this element's type. Because it is hard to guess what each schema author actually wants from anyType, mapping this type to C++ is hard. Some may want it not to contain anything since it is used as an abstract base class for all generated classes. Others may want it to contain a string representation of the content. And some may want a full-blown DOM fragment. To resolve this we decided to map anyType to a type that doesn't contain any data and to allow the user to customize it if necessary. Since this type doesn't contain anything, it is not clear how to compare two instances of it. Are they always equal? Or always unequal? I don't think any one of these options is particularly good so we left it unimplemented as some kind of a warning. In your case there are quite a few places where the schema uses anyType as an equivalent, it seems, for xsd:string (The XSD compiler warns of all such places). One way to resolve this would be to customize anyType and provide a string member which contains the data. Then you will be able to access this data and provide a sensible implementation for operator==. One tricky part of this customization is that you only want to extract and store the element's content if xml_schema::type is used by itself. If it is used as a base then that means the derived class will parse the data into the object model. The same goes for serialization. One way to detect this situation is to use the typeid operator. Here is an outline of how this might look: class type: xml_schema::type_base { public: type (const DOMElement& e, ...) { if (typeid (type) == typeid (*this)) { // anyType is used by itself; extract the text and store it in data_ } } const std::string& data () const { return data_; } void data (const std::string& data) { data_ = data; } private: std::string data_; }; There is the 'comments' example in the examples/cxx/tree/custom/ directory that shows how to customize anyType. Boris From boris at codesynthesis.com Fri Oct 9 13:23:49 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Compiling to multiple DLLs, duplicate symbols problem In-Reply-To: References: Message-ID: Hi Greg, [CC'ed xsd-users] Greg Carter writes: > Do you know if this problem persists in Visual Studio 2008? I am not 100% sure, but I think I tested it on 2008 and it had the same problem. Boris From greg at permedia.ca Fri Oct 9 16:21:52 2009 From: greg at permedia.ca (Greg Carter) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Compiling to multiple DLLs, duplicate symbols problem In-Reply-To: References: Message-ID: Hello Boris, That did the trick. I did need to add the -hxx-prologue option but I guess that is implied with the --export-symbol option. Thanks! Greg. Boris Kolpackov wrote: > Hi Greg, > > > The solution for this problem is to export symbols for the built-in types > from the "base" DLL and import them in all dependant DLLs and executables. > To automate this we added a new option, --export-xml-schema, for the next > release of XSD. You can give it a try by downloading this pre-release > binary: > > http://www.codesynthesis.com/~boris/tmp/xsd-3.3.0.a5-i686-windows.zip > > In your case, you will need to add > > --export-xml-schema --export-symbol GEOCOSMXMLBASE_SYMBOL_DECL > > when generating the code for the XML Schema namespace (i.e., "compiling" > XSDBaseXmlSchema.xsd). > > Let me know if this works for you. > > Boris > > From cerion at kestrel.ws Sat Oct 10 07:14:41 2009 From: cerion at kestrel.ws (Cerion Armour-Brown) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly Message-ID: <4AD06CA1.5030602@kestrel.ws> Hi all, I've been reading up on XSD - nice toolset! I'm very interested in using this - I believe this would make maintaining the changing xml schemas of my projects a simpler job I'm looking at porting Valkyrie, a frontend for Valgrind, to Qt4. Valgrind is a program analysis framework for and outputs xml on the fly to either log files or file-descriptors. I'm proposing to use C++/Tree as my memory model, but I don't see a simple way to parse (and display) the incoming xml chunks as they become available. Qt has xml reader functions parse() and parseContinue(), which one can use to read an xml file being written on the fly: one polls the file for updates, and calls parseContinue() whenever there's something new to be read. The reader keeps track of it's file position, so it's a very simple interface. (But, of course, Qt only provides the standard SAX/DOM parsers/models). => I'd like to know if there's a simple way of achieving the same thing using XSD? I imagine there would be, as there is talk of supporting RSS etc., but I can't work out how, or find examples. Would I have to use C++/Parser to build the Tree as complete events are read in? From my experiments, this looks plausible, but Parser still wants to read in the whole xml file in one go... I think I'd have to write a fair amount of code to set this up. I see in the mail archive an interesting reference (subject: CityGML 1.0.0 and C++/Parser interface) to the use of a custom SAX parser to read in chunk by chunk. Is this a good way to go? If so, there is mention of example code in the thread - is that available? Or perhaps I'd be better off going with an iostream (subject: Streaming, May 17 2007) ? If so, again, might there be example code available? (though for debugging it's always good to have Valgrind's direct XML output to analyse when things go wrong - then I'd have to tee the input stream or something... hmm). All advice, pointers, code examples!, etc would be very welcome! Many thanks, Cerion From jxmei3 at gmail.com Sun Oct 11 10:23:12 2009 From: jxmei3 at gmail.com (James Mei) Date: Sun Oct 11 15:34:11 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. Message-ID: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> Hi I have gone through the "Hello world" xsd tutorial with Borland C++ builder 2007. Everything works fine. I then proceed with generating more files from other xsd. ..\xsd cxx-tree --generate-serialization --namespace-map http://www.codesynthesis.com/xsd/SCL=SC_SCL *.xsd The main program, which just parse the xml file and save it to another: int main (int argc, char* argv[]) { try { using namespace SC_SCL; auto_ptr h (SCL_ (argv[1], xml_schema::flags::dont_validate)); ofstream outfile(argv[2], ios::out); SCL_(outfile, *h); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } } During compilation, it prompts the follow error: [BCC32 Error] SCL.cxx(273): E2093 'operator!' not implemented in type 'xsd::cxx::tree::optional' for arguments of the same type on the following line: if (n.name () == "Communication" && n.namespace_ () == " http://www.codesynthesis.com/xsd/SCL") { ::std::auto_ptr< Communication_type > r ( Communication_traits::create (i, f, this)); if (!this->Communication_) //<------------------------- error line { this->Communication_.set (r); continue; } } I changed the above line to if (this->Communication_==NULL) //<------------------------- changed { this->Communication_.set (r); continue; } The program compiles and run. However, there are 2 unexpected results. //Input XML file

1,1,1,999,1

12

00000001

0001

0001

209.254.235.118

........ //Output XML file ............. Unexpected result 1: All the tags has an "p1:" prefix. Unexpected result 2: It has no problem reading all the element names, but all the properties are missing. My questions 1. Did I do something wrong on modifying the line (if (!this->Communication_) ) to cause this result ? 2. I recompiled the whole program and xerces-c-3.0.1 using MingW, the unexpected result 2 is gone (all the property values appeared) but the unexpected result 1 ("p1") still remains. May I know how can I correct the above two problems ? Best regards James From boris at codesynthesis.com Mon Oct 12 05:52:21 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 12 05:45:23 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> Message-ID: Hi James, James Mei writes: > During compilation, it prompts the follow error: > > [BCC32 Error] SCL.cxx(273): E2093 'operator!' not implemented in type > 'xsd::cxx::tree::optional' for arguments of the same type The optional container implements "conversion to bool" via conversion to a function pointer. This is the recommended way but it is probably too much for BCB to handle. You can try to use the simpler but more dangerous approach by converting directly to bool. For this, change the following lines in libxsd/xsd/cxx/tree/containers.hxx: typedef optional self_; // Simplifier for Sun C++ 5.7. typedef void (self_::*bool_convertible) (); operator bool_convertible () const { return x_ != 0 ? &self_::true_ : 0; } To this: operator bool () const { return x_ != 0; } Note that there are two places in containers.hxx where you need to change this. > Unexpected result 1: All the tags has an "p1:" prefix. It is automatically assigned since you haven't specified the namespace- prefix mapping for http://www.codesynthesis.com/xsd/SCL (BTW, you probably don't want to use www.codesynthesis.com in your XML namespaces; if you need some dummy domain name, www.example.com is a good choice). If you want your output XML to look similar to the input, change your serialization code like so: xml_schema::namespace_infomap map; map[""].name = "http://www.codesynthesis.com/xsd/SCL"; map[""].schema = "SCL.xsd"; ofstream outfile(argv[2], ios::out); SCL_(outfile, *h, map); Boris From jxmei3 at gmail.com Mon Oct 12 07:41:13 2009 From: jxmei3 at gmail.com (James Mei) Date: Mon Oct 12 07:41:22 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> Message-ID: <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> Hi Boris Thanks for the fast reply. Really appreciate your help. After I changed the libxsd/xsd/cxx/tree/containers.hxx, the program compiles and run in BCB 2007. However it still does not read the properties value and has "p1" prefix in front of every tag. Here is the updated main program: int main (int argc, char* argv[]) { try { using namespace SC_SCL; auto_ptr h (SCL_ (argv[1], xml_schema::flags::dont_validate)); xml_schema::namespace_infomap map; map[""].name = "http://www.codesynthesis.com/xsd/SCL"; map[""].schema = "SCL.xsd"; ofstream outfile(argv[2], ios::out); SCL_ (outfile, *h, map); // SCL_(outfile, *h); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } } input XML

1,1,1,999,1

12

00000001

0001

0001

209.254.235.118

.................. Output XML Again, the "p1" prefix is still there and all the properties values are missing. Best Regards James On Mon, Oct 12, 2009 at 5:52 PM, Boris Kolpackov wrote: > Hi James, > > James Mei writes: > > > During compilation, it prompts the follow error: > > > > [BCC32 Error] SCL.cxx(273): E2093 'operator!' not implemented in type > > 'xsd::cxx::tree::optional' for arguments of the same type > > The optional container implements "conversion to bool" via conversion > to a function pointer. This is the recommended way but it is probably too > much for BCB to handle. You can try to use the simpler but more dangerous > approach by converting directly to bool. For this, change the following > lines in libxsd/xsd/cxx/tree/containers.hxx: > > typedef optional self_; // Simplifier for Sun C++ 5.7. > typedef void (self_::*bool_convertible) (); > > operator bool_convertible () const > { > return x_ != 0 ? &self_::true_ : 0; > } > > To this: > > operator bool () const > { > return x_ != 0; > } > > Note that there are two places in containers.hxx where you need to > change this. > > > > Unexpected result 1: All the tags has an "p1:" prefix. > > It is automatically assigned since you haven't specified the namespace- > prefix mapping for http://www.codesynthesis.com/xsd/SCL (BTW, you probably > don't want to use www.codesynthesis.com in your XML namespaces; if you > need > some dummy domain name, www.example.com is a good choice). > > If you want your output XML to look similar to the input, change your > serialization code like so: > > xml_schema::namespace_infomap map; > map[""].name = "http://www.codesynthesis.com/xsd/SCL"; > map[""].schema = "SCL.xsd"; > > ofstream outfile(argv[2], ios::out); > SCL_(outfile, *h, map); > > > Boris > From boris at codesynthesis.com Tue Oct 13 05:57:05 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 13 05:50:16 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: <4AD06CA1.5030602@kestrel.ws> References: <4AD06CA1.5030602@kestrel.ws> Message-ID: Hi Cerion, Cerion Armour-Brown writes: > I've been reading up on XSD - nice toolset! Thanks, glad you like it. > I'm proposing to use C++/Tree as my memory model, but I don't see a > simple way to parse (and display) the incoming xml chunks as they become > available. I was planning to come up with an example that shows how to do stream- oriented, partially in-memory parsing and serialization with C++/Tree for the next release. But seeing that you are looking for something like this, I went ahead and implemented it. Here is the excerpt from the README file: "This example shows how to perform stream-oriented, partially in-memory XML processing using the C++/Tree mapping. With the partially in-memory parsing and serialization only a part of the object model is in memory at any given time. With this approach we can process parts of the document as they become available as well as handle documents that are too large to fit into memory." I also backported this example to XSD 3.2.0: http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-streaming.tar.gz http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-streaming.zip It replaces the examples/cxx/tree/streaming example in XSD 3.2.0 which only shows the serialization part. So to use this example with 3.2.0, remove the examples/cxx/tree/streaming/ directory and then copy the content of one of the above archives into your XSD distribution directory. > Would I have to use C++/Parser to build the Tree as complete events are > read in? C++/Parser is inherently stream-oriented. That is, parsing will proceed and the callbacks will be called as data becomes available. C++/Tree is inherently in-memory, meaning you won't get to the data until the whole document is parsed. But, as the example above shows, C++/Tree can be used in a hybrid mode which is often exactly what you want since it doesn't require any manual coding (unlike C++/Parser, where you have to implement callbacks) and gives you all the benefits. > From my experiments, this looks plausible, but Parser still wants to read > in the whole xml file in one go. Not exactly. I think what you mean is that it doesn't return control until the whole file is parsed. With C++/Parser you would trigger displaying your data from one of the callback functions. > All advice, pointers, code examples!, etc would be very welcome! Let us know if you can come up with something based on the streaming example above. Boris From boris at codesynthesis.com Tue Oct 13 06:03:30 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 13 05:56:39 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> Message-ID: Hi James, James Mei writes: > After I changed the libxsd/xsd/cxx/tree/containers.hxx, the program compiles > and run in BCB 2007. However it still does not read the properties value This must be a bug in BCB, especially since it works with GCC. You can try to figure out what's going on by debugging the code. Maybe you can find a work-around. We don't test nor formally support this compiler because of its very poor quality. > and has "p1" prefix in front of every tag. > > [...] > > map[""].name = "http://www.codesynthesis.com/xsd/SCL"; > > [...] > > xmlns="http://www.iec.ch/61850/2003/SCL" Your document uses a different namespace so that's not surprising. Try to use the same namespace in both places: map[""].name = "http://www.iec.ch/61850/2003/SCL"; Boris From jxmei3 at gmail.com Tue Oct 13 08:06:42 2009 From: jxmei3 at gmail.com (James Mei) Date: Tue Oct 13 08:06:46 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> Message-ID: <550334c10910130506r3d22e98bo6ed10dc71916d890@mail.gmail.com> > > Hi Boris > Even I use the same namespace (no change on the namespace, write the xml file right after reading), it still has a "p1" prefix using namespace SC_SCL; auto_ptr h (SCL_ (argv[1], xml_schema::flags::dont_validate)); ofstream outfile(argv[2], ios::out); SCL_(outfile, *h); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } This happen for both Borland and GCC compiler. May I know what was wrong ? Cheers James > > > and has "p1" prefix in front of every tag. > > > > [...] > > > > map[""].name = "http://www.codesynthesis.com/xsd/SCL"; > > > > [...] > > > > xmlns="http://www.iec.ch/61850/2003/SCL" > > Your document uses a different namespace so that's not surprising. > Try to use the same namespace in both places: > > map[""].name = "http://www.iec.ch/61850/2003/SCL"; > > Boris > From boris at codesynthesis.com Tue Oct 13 09:54:14 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 13 09:47:33 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: <550334c10910130506r3d22e98bo6ed10dc71916d890@mail.gmail.com> References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> <550334c10910130506r3d22e98bo6ed10dc71916d890@mail.gmail.com> Message-ID: Hi James, James Mei writes: > Even I use the same namespace (no change on the namespace, write the xml > file right after reading), it still has a "p1" prefix Your schema and consequently your XML documents *DO* use namespaces. In the object model the information about the namespace-prefix mappings that was used in your input XML is not preserved. As a result, during serialization, you have two choices: you can either assign prefixes to namespaces used in your vocabulary manually, or generic ones (like p1, p2, etc.) will be assigned automatically. For details see Section 6.1, "Namespace and Schema Information" in the C++/Tree Mapping Getting Started Guide: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#6.1 > SCL_(outfile, *h); Change this to be: xml_schema::namespace_infomap map; map[""].name = "http://www.iec.ch/61850/2003/SCL"; map[""].schema = "SCL.xsd"; SCL_(outfile, *h, map); Boris From boris at codesynthesis.com Tue Oct 13 11:05:09 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 13 10:58:19 2009 Subject: [xsd-users] xs:choice representation in C++ In-Reply-To: References: Message-ID: Hi Ray, I've CC'ed xsd-users in case someone else is also has to handle something like this. Ray Lischner writes: > > Well, in this specific case, order for "to", "cc" and "bcc" elements is > > obviously not important. Most cases that I have seen would fall into > > this category. > > I don't know what most cases are, but I know for us, this particular > issue causes no small amount of pain. We have a list of choice of lists, > and the order is significant. Although we use and love Code Synthesis > elsewhere in the project, we cannot use Code Synthesis for this part. > Currently, we have a Java class handling this part of the project, but > there are plans to replace the Java class with C++, and I pity the > unfortunate who will not be able to use Code Synthesis. If it is a small part of the vocabulary (e.g., one or two types use this construct), then there are a couple of options that you can consider: 1. You can customize the type by providing an interface that preserves the order. While this will require you to do manual parsing for such types, the bulk of the vocabulary can still be handled automatically. 2. You can turn on the DOM association feature and traverse the content in the "document order" instead of the "object model order". Because you can go back from a DOM node to the corresponding object model node, you can still use the object model to actually access the data. That is, the DOM interface is only used for navigation in places where order is important. 3. You can customize xml_schema::type (base class for all the generated and built-in type) to include a "total order" counter (i.e., increment it every time a new object is created). This way all the nodes in the object model will have "parsing order" information. 4. If you can modify the schema then there is an elegant way to get rid of choice's altogether. This approach is described in detail in this post: http://www.codesynthesis.com/pipermail/xsd-users/2008-May/001697.html On the other hand, if the use of choice and the requirement to preserve order is spread throughout your schema then the only option I have is to use XSD/e and the C++/Hybird mapping: http://www.codesynthesis.com/products/xsde/ This mapping provides precise reproduction of XML vocabulary structure and element order in the object model. Boris From adam.chase1 at gmail.com Tue Oct 13 11:04:59 2009 From: adam.chase1 at gmail.com (Adam Chase) Date: Tue Oct 13 11:05:05 2009 Subject: [xsd-users] gdb macros for generated classes Message-ID: <17e364b30910130804j7d034b90xbed180ab4740ca67@mail.gmail.com> I am trying to debug some code that uses xsd generated C++ classes and would like to be able to print out their contents. Are there any gdb macros that I can use to do so? Any help would be appreciated. Sorry if this is a frequently asked question as I am new here. Adam From boris at codesynthesis.com Tue Oct 13 13:49:51 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 13 13:43:02 2009 Subject: [xsd-users] gdb macros for generated classes In-Reply-To: <17e364b30910130804j7d034b90xbed180ab4740ca67@mail.gmail.com> References: <17e364b30910130804j7d034b90xbed180ab4740ca67@mail.gmail.com> Message-ID: Hi Adam, Adam Chase writes: > I am trying to debug some code that uses xsd generated C++ classes and > would like to be able to print out their contents. > > Are there any gdb macros that I can use to do so? I am not aware of anything like this. Printing of the content of any generated class would require a specific macro for each class. I don't think this would scale. On the other hand, I can see how macros for printing the container templates (one, optional, sequence) that are used by the generated code could be useful. This could be similar to the macros used to print STL containers. One other thing that you may find useful is the option to generate ostream insertion operators (--generate-ostream). These can be used to quickly dump the content of the object model (or a fragment thereof) from the application. Boris From jxmei3 at gmail.com Tue Oct 13 19:14:48 2009 From: jxmei3 at gmail.com (James Mei) Date: Tue Oct 13 19:14:57 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: <550334c10910130850x5372ae61x9bca4bf99781b076@mail.gmail.com> References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> <550334c10910130506r3d22e98bo6ed10dc71916d890@mail.gmail.com> <550334c10910130850x5372ae61x9bca4bf99781b076@mail.gmail.com> Message-ID: <550334c10910131614s37dbc739kc7470e4c29db9094@mail.gmail.com> Hi Boris It seems like the serialization is trying to print out properties that stored in the class. But the properties are stored in unicode, that is why they are all missing in the output file. May I know if there is any flag setting to enable that ? e.g. ofstream outfile(argv[2], ios::out); SCL_(outfile, *h, f); //the value for "f" ? Or there is other API to store the xml file into the file system ? Cheers James On Tue, Oct 13, 2009 at 11:50 PM, James Mei wrote: > Hi Boris > > Thanks for the reply. > > I am currently tracing the line for the missing node properties. > > From the memory map, the Xerces parses the xml file correctly. It is then > putting the property values into the class structure. > > I can see the property values are stored in the class structure, but during > serialization, they do not get output. > > As show in the picture, the value for h.get()->Header().revision() is > stored in > > h._Myptr.Header.X_.revision_.x_ std::basic_string std::char_traits,std::allocator >::_Bx. > > Is there any special option in the serializer for the xml output ? > > Cheers > James > > > On Tue, Oct 13, 2009 at 9:54 PM, Boris Kolpackov wrote: > >> Hi James, >> >> James Mei writes: >> >> > Even I use the same namespace (no change on the namespace, write the xml >> > file right after reading), it still has a "p1" prefix >> >> Your schema and consequently your XML documents *DO* use namespaces. >> In the object model the information about the namespace-prefix mappings >> that was used in your input XML is not preserved. As a result, during >> serialization, you have two choices: you can either assign prefixes >> to namespaces used in your vocabulary manually, or generic ones (like >> p1, p2, etc.) will be assigned automatically. >> >> For details see Section 6.1, "Namespace and Schema Information" in the >> C++/Tree Mapping Getting Started Guide: >> >> >> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/guide/#6.1 >> >> >> > SCL_(outfile, *h); >> >> Change this to be: >> >> xml_schema::namespace_infomap map; >> >> map[""].name = "http://www.iec.ch/61850/2003/SCL"; >> map[""].schema = "SCL.xsd"; >> >> SCL_(outfile, *h, map); >> >> Boris >> > > From cerion at kestrel.ws Wed Oct 14 02:50:46 2009 From: cerion at kestrel.ws (Cerion Armour-Brown) Date: Wed Oct 14 02:50:54 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: References: <4AD06CA1.5030602@kestrel.ws> Message-ID: <4AD574C6.4020503@kestrel.ws> Boris, thanks for the quick response... Boris Kolpackov wrote: > Hi Cerion, > > Cerion Armour-Brown writes: >> I've been reading up on XSD - nice toolset! > Thanks, glad you like it. > >> I'm proposing to use C++/Tree as my memory model, but I don't see a >> simple way to parse (and display) the incoming xml chunks as they become >> available. > I was planning to come up with an example that shows how to do stream- > oriented, partially in-memory parsing and serialization with C++/Tree > for the next release. But seeing that you are looking for something > like this, I went ahead and implemented it. Here is the excerpt from > the README file: > > "This example shows how to perform stream-oriented, partially in-memory > XML processing using the C++/Tree mapping. With the partially in-memory > parsing and serialization only a part of the object model is in memory at > any given time. With this approach we can process parts of the document > as they become available as well as handle documents that are too large > to fit into memory." > > I also backported this example to XSD 3.2.0: > > http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-streaming.tar.gz > http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-streaming.zip > > It replaces the examples/cxx/tree/streaming example in XSD 3.2.0 which > only shows the serialization part. So to use this example with 3.2.0, > remove the examples/cxx/tree/streaming/ directory and then copy the > content of one of the above archives into your XSD distribution > directory. I'll take a proper look as soon as I can, but this does look interesting... Not quite clear on one point tho: I see the current example reads in chunks and holds in memory the latest chunk... but I'd need to build up a complete model, reading in chunk by chunk. Not sure if this is a simple step to take. And if that is possible, I guess I'd then poll the input file for changes, and call parser->next() if there's anything new... Background: A valgrind process can be running for hours (or even days!), hence the need for the user to see what's happening as it happens: don't want to wait for the process to end before finding out that something bad happened after 5mins and we should have killed it :-) >> Would I have to use C++/Parser to build the Tree as complete events are >> read in? >> > C++/Parser is inherently stream-oriented. That is, parsing will proceed > and the callbacks will be called as data becomes available. C++/Tree is > inherently in-memory, meaning you won't get to the data until the whole > document is parsed. But, as the example above shows, C++/Tree can be used > in a hybrid mode which is often exactly what you want since it doesn't > require any manual coding (unlike C++/Parser, where you have to implement > callbacks) and gives you all the benefits. > >> From my experiments, this looks plausible, but Parser still wants to read >> in the whole xml file in one go. >> > Not exactly. I think what you mean is that it doesn't return control until > the whole file is parsed. With C++/Parser you would trigger displaying your > data from one of the callback functions. > You're absolutely correct... I was approaching this from the Qt pov. So if I went this route, I'd need to run the C++/Parser within a separate thread... fair enough. >> All advice, pointers, code examples!, etc would be very welcome! > Let us know if you can come up with something based on the streaming > example above. > > Boris Thanks for your help, Cerion From boris at codesynthesis.com Wed Oct 14 10:38:31 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 14 10:31:48 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: <4AD574C6.4020503@kestrel.ws> References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> Message-ID: Hi Cerion, Cerion Armour-Brown writes: > I'll take a proper look as soon as I can, but this does look interesting... > Not quite clear on one point tho: I see the current example reads in > chunks and holds in memory the latest chunk... but I'd need to build up > a complete model, reading in chunk by chunk. Not sure if this is a > simple step to take. Yes, that's quite easy. Here is a modified fragment from the example that constructs the entire object model: xml_schema::dom::auto_ptr doc (p.start (ifs, argv[1], true)); // Find the id attribute. // DOMAttr* id_attr ( doc->getDocumentElement ()->getAttributeNode ( xml::string ("id").c_str ())); // Use the type and traits aliases from the object model. // object::id_type id (object::id_traits::create (*id_attr, 0, 0)); // The next chunk we get is the header element. // doc = p.next (); header hdr (*doc->getDocumentElement ()); object obj (hdr, id); // The rest is position elements. // for (doc = p.next (); doc.get () != 0; doc = p.next ()) { // Dynamically allocate position instances so that obj can assume // their ownership without copying. // auto_ptr p (new position (*doc->getDocumentElement (), 0, &obj)); obj.position ().push_back (p); } > And if that is possible, I guess I'd then poll the input file for > changes, and call parser->next() if there's anything new... That's not how it works, actually. You see, the next() call can only return at certain points in the document structure. For example, it cannot return after half of an element's name has been parsed. In this case, it will keep calling read() on the stream (and blocking if there is no data) until it reaches a point in the document structure where it can return a complete DOM chunk. I guess if the producer of your XML guarantees that the data will be written one first level element at a time, then this will work as expected. If that's not the case then you will need to make another plan (e.g., run the parser in a separate thread). Boris From boris at codesynthesis.com Wed Oct 14 10:53:53 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 14 10:47:10 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: <550334c10910131614s37dbc739kc7470e4c29db9094@mail.gmail.com> References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> <550334c10910130506r3d22e98bo6ed10dc71916d890@mail.gmail.com> <550334c10910130850x5372ae61x9bca4bf99781b076@mail.gmail.com> <550334c10910131614s37dbc739kc7470e4c29db9094@mail.gmail.com> Message-ID: Hi James, James Mei writes: > Hi Boris > > It seems like the serialization is trying to print out properties that > stored in the class. But the properties are stored in unicode, that is why > they are all missing in the output file. I am not sure I understand what you mean. The input XML, strings in the program, and the output XML all use UTF-8 encoding. Also the values involved are in plain ASCII. So I don't think this has anything to do with Unicode. You said that the properties end up in the object model. Then the problem is somewhere between that and the output XML. I suggest that you find the serialization operator for the tP type in the generated code (void operator<< (DOMElement&, const tP&)), set a breakpoint in its body and see what's going on by stepping through all the code that gets executed from that point. Boris From bpringle at sympatico.ca Wed Oct 14 12:32:04 2009 From: bpringle at sympatico.ca (Bill Pringlemeir) Date: Wed Oct 14 11:19:05 2009 Subject: [xsd-users] gdb macros for generated classes In-Reply-To: (Boris Kolpackov's message of "Tue, 13 Oct 2009 19:49:51 +0200") References: <17e364b30910130804j7d034b90xbed180ab4740ca67@mail.gmail.com> Message-ID: <87fx9mx7gb.fsf@sympatico.ca> On 13 Oct 2009, boris@codesynthesis.com wrote: > Adam Chase writes: >> I am trying to debug some code that uses xsd generated C++ classes and >> would like to be able to print out their contents. >> Are there any gdb macros that I can use to do so? > I am not aware of anything like this. Printing of the content of any > generated class would require a specific macro for each class. I don't > think this would scale. On the other hand, I can see how macros for > printing the container templates (one, optional, sequence) that are > used by the generated code could be useful. This could be similar to > the macros used to print STL containers. There are some gdb environment values that will pretty print classes, display/not display the vtable, etc. You can traverse many of the values by using brackets and the confounded 'x_' member (afair). It is not necessary to use casts and doing so will generally give you errors about the value not be available. I had considered writing some macros and it *seems* that you could do this with gdb. I would guess that you have some complex type with say an int, a string, and a restriction. When you print this type, you just get a bunch of, p = {{ DOM:type int, x_}, { DOM:type string, x_}, { DOM:type string, x_}} I think you want, p = { 21, "foo", "bar" }; The above is not the exact output from gdb... but I think it covers the dilemma? The p in this case has three instances of the 'one' type. For users of XSD, the machinery of one, optional, sequence are not usually too relevant. Usually you need access to the data binding values to debug an application layer problem. These are rightfully hidden following good OO practices, but this obfuscates debugging. People might not wish to include debug printing as this isn't needed in production. Core dumps from production environments may not have this, making intermittent problems difficult to trace if this is the mechanism used. All of the information is available in gdb. In the above example, there are many brackets, 'x_', '->', '.' and '*' which can get from one form to the next. fwiw, Bill Pringlemeir. From boris at codesynthesis.com Wed Oct 14 11:03:10 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 14 14:07:24 2009 Subject: [xsd-users] gdb macros for generated classes In-Reply-To: <17e364b30910131148o36d6ef1bq3c7aa8824156d816@mail.gmail.com> References: <17e364b30910130804j7d034b90xbed180ab4740ca67@mail.gmail.com> <17e364b30910131148o36d6ef1bq3c7aa8824156d816@mail.gmail.com> Message-ID: Hi Adam, In the future please keep your replies CC'ed to the xsd-users mailing list as discussed in the posting guidelines: http://www.codesynthesis.com/support/posting-guidelines.xhtml Adam Chase writes: > > I am not aware of anything like this. Printing of the content of any > > generated class would require a specific macro for each class. I don't > > think this would scale. On the other hand, I can see how macros for > > printing the container templates (one, optional, sequence) that are > > used by the generated code could be useful. This could be similar to > > the macros used to print STL containers. > > > > I think this would be great. If I'm looking at a core dump I can't > call any of the method accessors to see what kind of data I'm looking > at. If someone is willing to come up with something like this, I will gladly include it into the XSD distribution. > > One other thing that you may find useful is the option to generate > > ostream insertion operators (--generate-ostream). These can be used > > to quickly dump the content of the object model (or a fragment thereof) > > from the application. > > This is a good idea as well. Can I use ostream for dumping objs when > examining a core file? Hm, I don't think you can execute any code at this stage. Though there are rumors of support for reverse execution in gdb 7, so who knows. If that is not possible, I guess the next best thing would be to see where the program crashes and try to dump the object model as close to this place as possible. Boris From cerion at kestrel.ws Wed Oct 14 18:00:38 2009 From: cerion at kestrel.ws (Cerion Armour-Brown) Date: Wed Oct 14 18:00:47 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> Message-ID: <4AD64A06.4070205@kestrel.ws> Hi Boris, Boris Kolpackov wrote: > Cerion Armour-Brown writes: >> 'll take a proper look as soon as I can, but this does look interesting... >> Not quite clear on one point tho: I see the current example reads in >> chunks and holds in memory the latest chunk... but I'd need to build up >> a complete model, reading in chunk by chunk. Not sure if this is a >> simple step to take. >> > Yes, that's quite easy. Here is a modified fragment from the example > that constructs the entire object model: > > ... > > // The rest is position elements. > // > for (doc = p.next (); doc.get () != 0; doc = p.next ()) > { > // Dynamically allocate position instances so that obj can assume > // their ownership without copying. > // > auto_ptr p (new position (*doc->getDocumentElement (), 0, &obj)); > obj.position ().push_back (p); > } > Ok, that's straightforward, and I'm glad to see we can 'reparent', avoiding a deep copy. Unfortunately, the ordering of the elements is not as simple as in this example: during parsing we could receive one of a few different element types. I guess this approach would require me to take a look at the content of DocumentElement first, before allocating and intantiating a particular element type. Or do you see a better way? >> And if that is possible, I guess I'd then poll the input file for >> changes, and call parser->next() if there's anything new... >> > That's not how it works, actually. You see, the next() call can only > return at certain points in the document structure. For example, it > cannot return after half of an element's name has been parsed. In > this case, it will keep calling read() on the stream (and blocking > if there is no data) until it reaches a point in the document structure > where it can return a complete DOM chunk. > You say it will block if there's no data: when I try the examples out using files, an error is thrown when EOF is read instead of the expected xml. Hence my understanding that one would need to poll to make sure the read will succeed... Am I missing something? > I guess if the producer of your XML guarantees that the data will be > written one first level element at a time, then this will work as > expected. If that's not the case then you will need to make another > plan (e.g., run the parser in a separate thread). > That could be an acceptable requirement, but I'd much prefer not to assume anything about the incoming data stream, so I think a separate thread it will have to be. Hmm. I'm wondering if I wouldn't be better of starting with the C++/Parser? Assuming I can make use of the auto-generated implementation, I could run the parser in a separate thread, leaving it in a blocking read, updating a shared memory model in post_ methods of document-level elements (and at the same time flagging the GUI thread that the model has been updated). What do you advise? Note: If you advise the hybrid/Tree direction, then please ignore the following :-) I had quick go at the Parser "generated" example, and see potential, but have a question about the input stream: As for the Tree examples, I'm missing something as to how the streaming principle works: If a file is used, the callbacks are called as expected as the xml is read and parsed, but an error is thrown if EOF is reached before the closing tag is read. Am I supposed to catch this 'error' and retry parsing until the document is finished? If istream is used, the parse() function blocks as it should, but the callbacks are not called until the entire xml document has been read in: I would have expected the callbacks to be executed as each block parsing is read in, so one can react to xml block as they arrive. What am I missing/misunderstanding? Cheers, Cerion From boris at codesynthesis.com Thu Oct 15 09:01:47 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 15 08:55:11 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: <4AD64A06.4070205@kestrel.ws> References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> <4AD64A06.4070205@kestrel.ws> Message-ID: Hi Cerion, Cerion Armour-Brown writes: > Unfortunately, the ordering of the elements is not as simple as in this > example: during parsing we could receive one of a few different element > types. I guess this approach would require me to take a look at the > content of DocumentElement first, before allocating and intantiating a > particular element type. Yes, that's how you can handle this situation. There is an example called multiroot that shows how to do this in the context of handling XML documents with varying root elements. > You say it will block if there's no data: when I try the examples out > using files, an error is thrown when EOF is read instead of the expected > xml. Hence my understanding that one would need to poll to make sure > the read will succeed... Am I missing something? If the stream ends with EOF then the parser assume there is no more data available. And if the document is incomplete, then you will get a parsing error. In your case, I guess, you will need to provide a custom std::istream implementation (or xercesc::InputSource -- that could actually be easier) that doesn't return on EOF but instead keeps polling the file for more data (e.g., you could save the offset of the last byte read, wait some time, re-open the file, seek to that saved offset, and see if there is more data). I assume you will need to implement this logic somewhere in the application in any case. With this approach it will just be in the stream. > Hmm. I'm wondering if I wouldn't be better of starting with the > C++/Parser? Assuming I can make use of the auto-generated implementation, > I could run the parser in a separate thread, leaving it in a blocking > read, updating a shared memory model in post_ methods of document-level > elements (and at the same time flagging the GUI thread that the model > has been updated). What do you advise? The auto-generated implementation is just a stub. You will still need to provide your own classes that actually store the data as well as populate them from the callbacks. You will also have the same issue with EOF as in the C++/Tree model. Boris From jxmei3 at gmail.com Thu Oct 15 09:55:39 2009 From: jxmei3 at gmail.com (James Mei) Date: Thu Oct 15 09:55:45 2009 Subject: [xsd-users] Help me: How do I redirect the exception message from console output to a memory buffer Message-ID: <550334c10910150655o2d671fb1p562f975ca14af610@mail.gmail.com> Hi May I know how do I get/redirect the exception message (mainly for validation), from cerr to a memory buffer so that I can pipe to a file or reformat it on the screen ? Best regards James From jxmei3 at gmail.com Thu Oct 15 10:06:10 2009 From: jxmei3 at gmail.com (James Mei) Date: Thu Oct 15 10:06:21 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: References: <550334c10910110723u671f53fah5a61570d5490395c@mail.gmail.com> <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> <550334c10910130506r3d22e98bo6ed10dc71916d890@mail.gmail.com> <550334c10910130850x5372ae61x9bca4bf99781b076@mail.gmail.com> <550334c10910131614s37dbc739kc7470e4c29db9094@mail.gmail.com> <550334c10910141708u1f18282l31dea22050ef2568@mail.gmail.com> Message-ID: <550334c10910150706v75d46727j65bcb44be1b3e75e@mail.gmail.com> Hi Boris Thanks for the advice. I managed to get the BCB2009 to work. But I still take your advice and tested xsd with VC++ express 2008 and pro 2008. the programs generated by these compilers produces different XML files for the same schema. When a xml is parsed and serialized, there are extra attributes for the program compiled by vc pro 2008: by vc++ pro 2008 ================================================= status-only SEL FID=SEL-421-3-R123-V0-Z010010-D20070223 Annunciation by vc++ express 2008 ================================================= status-only SEL FID=SEL-421-3-R123-V0-Z010010-D20070223 Annunciation ix="3452816845", sGroup="3452816845" are not part of the schema and do not exist in the program output generated by vc express 2008. Also, the decimal value of 3452816845 is HEX 0xCDCDCDCD, does it mean anything ? I also have trouble compiling the program into a dll following the step guild. I will keep testing and give more detail later. Since this is moving away from Borland compiler, should I open another topic ? Cheers James On Thu, Oct 15, 2009 at 9:10 PM, Boris Kolpackov wrote: > Hi James, > > James Mei writes: > > > From your expert experience, do you have any idea what might be the cause > > for "Debug information" requirement in BCB2009 ? > > I think this is a bug in the compiler. Seeing that this is Borland C++, I > am not surprised at all. Have you considered changing to something of > better quality? VC++ Express edition is free and works great with XSD. > > Boris > From boris at codesynthesis.com Fri Oct 16 04:52:44 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Oct 16 04:46:11 2009 Subject: [xsd-users] Help me: How do I redirect the exception message from console output to a memory buffer In-Reply-To: <550334c10910150655o2d671fb1p562f975ca14af610@mail.gmail.com> References: <550334c10910150655o2d671fb1p562f975ca14af610@mail.gmail.com> Message-ID: Hi James, James Mei writes: > May I know how do I get/redirect the exception message (mainly for > validation), from cerr to a memory buffer so that I can pipe to a file > or reformat it on the screen ? You can use std::ostringstream to serialize the diagnostics to a string. You can also programmatically access each parsing/serialization diagnostics message by catching the xml_schema::parsing and/or xml_schema::validation exceptions and using their accessors to extract this information. For details, see Section 3.3, "Error Handling" in the C++/Tree Mapping User Manual: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#3.3 Boris From boris at codesynthesis.com Fri Oct 16 05:03:37 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Oct 16 04:57:04 2009 Subject: [xsd-users] Help me: Borland C++ Builder 2007 compiled program has unwanted prefix and all property values are missing. In-Reply-To: <550334c10910150706v75d46727j65bcb44be1b3e75e@mail.gmail.com> References: <550334c10910120441i104e9391w1e0ea21fe33af073@mail.gmail.com> <550334c10910130506r3d22e98bo6ed10dc71916d890@mail.gmail.com> <550334c10910130850x5372ae61x9bca4bf99781b076@mail.gmail.com> <550334c10910131614s37dbc739kc7470e4c29db9094@mail.gmail.com> <550334c10910141708u1f18282l31dea22050ef2568@mail.gmail.com> <550334c10910150706v75d46727j65bcb44be1b3e75e@mail.gmail.com> Message-ID: Hi James, James Mei writes: > ix="3452816845", sGroup="3452816845" are not part of the schema and do > not exist in the program output generated by vc express 2008. They are part of the schema. > Also, the decimal value of 3452816845 is HEX 0xCDCDCDCD, does it mean > anything ? It is most likely garbage. I suspect that you are trying this with XSD source code that you have modified. Can you try it on the standard XSD distribution without any modifications? Double check that the include paths in VC++ point to the unmodified libxsd. > Since this is moving away from Borland compiler, should I open another > topic Yes, the posting guidelines suggest that you should start a new email (instead of replying to an existing thread) with a new subject for an unrelated questions: http://www.codesynthesis.com/support/posting-guidelines.xhtml Boris From jxmei3 at gmail.com Fri Oct 16 05:03:43 2009 From: jxmei3 at gmail.com (James Mei) Date: Fri Oct 16 05:03:46 2009 Subject: [xsd-users] Help me: VC pro and VC express generate different XML Message-ID: <550334c10910160203y36735c65yf3776529cc365a84@mail.gmail.com> Hi Boris > > > ix="3452816845", sGroup="3452816845" are not part of the schema and do > > not exist in the program output generated by vc express 2008. > > They are part of the schema. > If it is part of the schema, then VC express should generate this entries as well. But it has no where exists in the xsd file. > > > Also, the decimal value of 3452816845 is HEX 0xCDCDCDCD, does it mean > > anything ? > > It is most likely garbage. I suspect that you are trying this with XSD > source code that you have modified. Can you try it on the standard XSD > distribution without any modifications? Double check that the include > paths in VC++ point to the unmodified libxsd. > I have now regenerated the source file, but the same thing happened. However, the program compiled with BCB2009 produces one sGroup attribute in one of the TAG. None exist in the program compiled by VC express 2008. Lots of those ix, sGroup entries in the program compiled by VC pro. Any idea ? Cheers James From jxmei3 at gmail.com Fri Oct 16 20:10:07 2009 From: jxmei3 at gmail.com (James Mei) Date: Fri Oct 16 20:10:17 2009 Subject: [xsd-users] Re: Help me: VC pro and VC express generate different XML In-Reply-To: <550334c10910160203y36735c65yf3776529cc365a84@mail.gmail.com> References: <550334c10910160203y36735c65yf3776529cc365a84@mail.gmail.com> Message-ID: <550334c10910161710u68b1508fu83ed872e408cba2e@mail.gmail.com> Hi Boris I just found out that ix and sGroup is part of the schema as optional items. The strange part for VC++ express and VC++ Pro 2008 is that: Same source code but one compiler program produces those attributes (VC++ pro) and one does not (VC++ express). BTW, the original xml file does not have those attributes. I also found out that the strange number at the back ix="3452816845", is the actual pointer value of the attribute. Any idea ? ///////////////////////////////////////////////////////Source int _tmain(int argc, _TCHAR* argv[]) { try { using namespace SC_SCL; auto_ptr h (SCL_ (argv[1], xml_schema::flags::dont_validate)); ofstream outfile(argv[2], ios::out); SCL_(outfile, *h); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } } ////////////////////////////// Also notice the constructor of the xsd class (SCL) does not take wchar_t* as input filename. It has to be char *. Is there anyway to make it unicode compatible ? Cheers James On Fri, Oct 16, 2009 at 5:03 PM, James Mei wrote: > Hi Boris > >> >> > ix="3452816845", sGroup="3452816845" are not part of the schema and do >> > not exist in the program output generated by vc express 2008. >> >> They are part of the schema. >> > > If it is part of the schema, then VC express should generate this entries > as well. But it has no where exists in the xsd file. > >> >> > Also, the decimal value of 3452816845 is HEX 0xCDCDCDCD, does it mean >> > anything ? >> >> It is most likely garbage. I suspect that you are trying this with XSD >> source code that you have modified. Can you try it on the standard XSD >> distribution without any modifications? Double check that the include >> paths in VC++ point to the unmodified libxsd. >> > > I have now regenerated the source file, but the same thing happened. > However, the program compiled with BCB2009 produces one sGroup attribute in > one of the TAG. None exist in the program compiled by VC express 2008. Lots > of those ix, sGroup entries in the program compiled by VC pro. > > Any idea ? > > Cheers > James > From cerion at kestrel.ws Sun Oct 18 05:01:12 2009 From: cerion at kestrel.ws (Cerion Armour-Brown) Date: Sun Oct 18 05:01:21 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> <4AD64A06.4070205@kestrel.ws> Message-ID: <4ADAD958.4000905@kestrel.ws> Hi Boris, Boris Kolpackov wrote: > Cerion Armour-Brown writes: >> You say it will block if there's no data: when I try the examples out >> using files, an error is thrown when EOF is read instead of the expected >> xml. Hence my understanding that one would need to poll to make sure >> the read will succeed... Am I missing something? >> > > If the stream ends with EOF then the parser assume there is no more > data available. And if the document is incomplete, then you will get > a parsing error. In your case, I guess, you will need to provide a > custom std::istream implementation (or xercesc::InputSource -- that > could actually be easier) that doesn't return on EOF but instead keeps > polling the file for more data (e.g., you could save the offset of the > last byte read, wait some time, re-open the file, seek to that saved > offset, and see if there is more data). I assume you will need to > implement this logic somewhere in the application in any case. With > this approach it will just be in the stream. > I had a look at doing this, but this I'm not happy about this direction. Xerces buffers the file data, and if the buffer gets low, it reads ahead. This means there may be data available to xerces (in its buffer), but we're going to block on the file anyway. Plus I would need to take a look at the data last read from the file (i.e. in xerces buffer, or seek back in the file), to see if EOF has been reached correctly (closing tag has been read in). I find this too sensitive to the underlying xerces implementation (and more work than I'd hoped for!) If I can avoid it, I'd prefer not to work with separate threads at all (the above blocking read solution would need that). I imagined my Qt app could be the driver, with a loop to pull in the next (few) top level tags, and then update the GUI, and so on. This simplifies the whole setup, and keeps Qt in control. Qt solves this EOF problem by returning an UnexpectedEOF error, but make this recoverable, so we can continue parsing. From what I understand from the docs and source code, XSD / Xerces don't (yet) support recovery from this? If they do, how is this possible, and is this a way forward? I don't even see how I can identify the error well - it seems the error type number isn't propagated, only the message string, and I'm not going to match on that! Thanks again for you help thus far, it's appreciated. Cerion P.S. Do you have plans to make a xml binder for the Qt parsers? ;-) From jxmei3 at gmail.com Sun Oct 18 05:26:28 2009 From: jxmei3 at gmail.com (James Mei) Date: Sun Oct 18 05:26:36 2009 Subject: [xsd-users] Help me: How do I redirect the exception message from console output to a memory buffer In-Reply-To: References: <550334c10910150655o2d671fb1p562f975ca14af610@mail.gmail.com> Message-ID: <550334c10910180226v73e0e0bfv201660d775be40bb@mail.gmail.com> Hi Boris You can use std::ostringstream to serialize the diagnostics to a string. > Do you have an example on doing it ? You can also programmatically access each parsing/serialization diagnostics message by catching the xml_schema::parsing and/or xml_schema::validation > exceptions and using their accessors to extract this information. For > details, see Section 3.3, "Error Handling" in the C++/Tree Mapping User > Manual: > > > http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#3.3 > I have tried doing it, it seems like I did something wrong in the auto_ptr and it will not compile. #include #include #include "scl\SCL.hxx" using namespace std; class error_handler { public: struct severity { enum value { warning, error, fatal }; }; virtual bool handle (const std::basic_string& id, unsigned long line, unsigned long column, severity, const std::basic_string& message) = 0; virtual ~error_handler (); }; //implementation bool error_handler::handle (const std::basic_string& id, unsigned long line, unsigned long column, severity, const std::basic_string& message) { cout << id << message << endl; } int main (int argc, char* argv[]) { try { using namespace SC_SCL; //I am trying to use the following // ::std::auto_ptr< ::SC_SCL::SCL > // SCL_ (const ::std::string& u, // ::xml_schema::error_handler& h, // ::xml_schema::flags f, // const ::xml_schema::properties& p) error_handler *eh; //compilation error Could not find a match for 'SCL_(char *,xml_schema::error_handler *,const unsigned long,int)' auto_ptr h (SCL_(argv[1], (::xml_schema::error_handler *)eh, 0, NULL)); //not using xml_schema::flags::dont_validate h.get()->Header().revision("abc"); xml_schema::namespace_infomap map; map[""].name = "http://www.iec.ch/61850/2003/SCL"; map[""].schema = "SCL.xsd"; ofstream outfile(argv[2], ios::out); SCL_ (outfile, *h, map); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } } May I know what is the correct way to implement the "error_handler" ? Cheers From jxmei3 at gmail.com Sun Oct 18 07:35:21 2009 From: jxmei3 at gmail.com (James Mei) Date: Sun Oct 18 07:35:29 2009 Subject: [xsd-users] Help me: How do I redirect the exception message from console output to a memory buffer In-Reply-To: <550334c10910180226v73e0e0bfv201660d775be40bb@mail.gmail.com> References: <550334c10910150655o2d671fb1p562f975ca14af610@mail.gmail.com> <550334c10910180226v73e0e0bfv201660d775be40bb@mail.gmail.com> Message-ID: <550334c10910180435l15df12e4y33a0500d19408693@mail.gmail.com> Hi Boris I have found the mistake, I did not inherit the abstract class. Here is the result class MyErrorHandle : public ::xml_schema::error_handler { public: MyErrorHandle() { } // template bool handle (const std::basic_string& id, unsigned long line, unsigned long column, severity, const std::basic_string& message) { cout << id << message << endl; return true; } ~MyErrorHandle () { } }; int main (int argc, char* argv[]) { try { using namespace SC_SCL; MyErrorHandle *eh = new MyErrorHandle(); // auto_ptr h (SCL_(argv[1], *eh, xml_schema::flags::dont_validate, p)); auto_ptr h (SCL_(argv[1], *eh, 0, p)); h.get()->Header().revision("abc"); xml_schema::namespace_infomap map; map[""].name = "http://www.iec.ch/61850/2003/SCL"; map[""].schema = "SCL.xsd"; ofstream outfile(argv[2], ios::out); SCL_ (outfile, *h, map); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } } Cheers James On Sun, Oct 18, 2009 at 5:26 PM, James Mei wrote: > Hi Boris > > > You can use std::ostringstream to serialize the diagnostics to a string. >> > > Do you have an example on doing it ? > > You can also programmatically access each parsing/serialization >> diagnostics > > message by catching the xml_schema::parsing and/or xml_schema::validation >> exceptions and using their accessors to extract this information. For >> details, see Section 3.3, "Error Handling" in the C++/Tree Mapping User >> Manual: >> >> >> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#3.3 >> > > I have tried doing it, it seems like I did something wrong in the > auto_ptr and it will not compile. > > #include > #include > #include "scl\SCL.hxx" > > using namespace std; > > class error_handler > { > public: > struct severity > { > enum value > { > warning, > error, > fatal > }; > }; > > virtual bool > handle (const std::basic_string& id, > unsigned long line, > unsigned long column, > severity, > const std::basic_string& message) = 0; > > virtual > ~error_handler (); > }; > //implementation > bool > error_handler::handle (const std::basic_string& id, > unsigned long line, > unsigned long column, > severity, > const std::basic_string& message) > { > cout << id << message << endl; > } > > > int main (int argc, char* argv[]) > { > try > { > using namespace SC_SCL; > //I am trying to use the following > // ::std::auto_ptr< ::SC_SCL::SCL > > // SCL_ (const ::std::string& u, > // ::xml_schema::error_handler& h, > // ::xml_schema::flags f, > // const ::xml_schema::properties& p) > error_handler *eh; > //compilation error Could not find a match for 'SCL_(char > *,xml_schema::error_handler *,const unsigned long,int)' > auto_ptr h (SCL_(argv[1], (::xml_schema::error_handler *)eh, 0, > NULL)); //not using xml_schema::flags::dont_validate > > h.get()->Header().revision("abc"); > xml_schema::namespace_infomap map; > > map[""].name = "http://www.iec.ch/61850/2003/SCL"; > map[""].schema = "SCL.xsd"; > > ofstream outfile(argv[2], ios::out); > SCL_ (outfile, *h, map); > } > catch (const xml_schema::exception& e) > { > cerr << e << endl; > return 1; > } > } > > May I know what is the correct way to implement the "error_handler" ? > > Cheers > > > From jxmei3 at gmail.com Fri Oct 16 22:33:33 2009 From: jxmei3 at gmail.com (James Mei) Date: Mon Oct 19 09:25:13 2009 Subject: [xsd-users] Re: Help me: VC pro and VC express generate different XML In-Reply-To: <550334c10910161710u68b1508fu83ed872e408cba2e@mail.gmail.com> References: <550334c10910160203y36735c65yf3776529cc365a84@mail.gmail.com> <550334c10910161710u68b1508fu83ed872e408cba2e@mail.gmail.com> Message-ID: <550334c10910161933t1cc1037fx7ee727d8289ec495@mail.gmail.com> Hi Boris Please find the VC project/source attached with all schema files. The Program compiled with VC++ Pro 2008 will generates extra attributes "ix" and "sGroup". If the same source is compiled with VC++ express 2008, ix and sGroup will not be there. Please use the file "1" as the source xml file. (use run.bat) BTW, ix is an optional attribute, but sGroup is not. It does not exist in the schema. Intially I though it was "SettingGroups" attribute, but the element name does not match. I am not sure where "sGroup" comes from. Could you take a look what did I set wrong here ? Best regards James On Sat, Oct 17, 2009 at 8:10 AM, James Mei wrote: > Hi Boris > > I just found out that ix and sGroup is part of the schema as optional > items. > > The strange part for VC++ express and VC++ Pro 2008 is that: > > Same source code but one compiler program produces those attributes (VC++ > pro) and one does not (VC++ express). BTW, the original xml file does not > have those attributes. > > I also found out that the strange number at the back ix="3452816845", is > the actual pointer value of the attribute. > > Any idea ? > > ///////////////////////////////////////////////////////Source > int _tmain(int argc, _TCHAR* argv[]) > { > try > { > using namespace SC_SCL; > auto_ptr h (SCL_ (argv[1], xml_schema::flags::dont_validate)); > > ofstream outfile(argv[2], ios::out); > SCL_(outfile, *h); > } > catch (const xml_schema::exception& e) > { > cerr << e << endl; > return 1; > } > } > > ////////////////////////////// > > Also notice the constructor of the xsd class (SCL) does not take wchar_t* > as input filename. It has to be char *. Is there anyway to make it unicode > compatible ? > > Cheers > James > > > On Fri, Oct 16, 2009 at 5:03 PM, James Mei wrote: > >> Hi Boris >> >>> >>> > ix="3452816845", sGroup="3452816845" are not part of the schema and do >>> > not exist in the program output generated by vc express 2008. >>> >>> They are part of the schema. >>> >> >> If it is part of the schema, then VC express should generate this entries >> as well. But it has no where exists in the xsd file. >> >>> >>> > Also, the decimal value of 3452816845 is HEX 0xCDCDCDCD, does it mean >>> > anything ? >>> >>> It is most likely garbage. I suspect that you are trying this with XSD >>> source code that you have modified. Can you try it on the standard XSD >>> distribution without any modifications? Double check that the include >>> paths in VC++ point to the unmodified libxsd. >>> >> >> I have now regenerated the source file, but the same thing happened. >> However, the program compiled with BCB2009 produces one sGroup attribute in >> one of the TAG. None exist in the program compiled by VC express 2008. Lots >> of those ix, sGroup entries in the program compiled by VC pro. >> >> Any idea ? >> >> Cheers >> James >> > > -------------- next part -------------- A non-text attachment was scrubbed... Name: VC++ Project.zip Type: application/zip Size: 35270 bytes Desc: not available Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20091017/c00902c1/VCProject-0001.zip From boris at codesynthesis.com Mon Oct 19 10:11:56 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 19 10:05:48 2009 Subject: [xsd-users] Re: Help me: VC pro and VC express generate different XML In-Reply-To: <550334c10910161933t1cc1037fx7ee727d8289ec495@mail.gmail.com> References: <550334c10910160203y36735c65yf3776529cc365a84@mail.gmail.com> <550334c10910161710u68b1508fu83ed872e408cba2e@mail.gmail.com> <550334c10910161933t1cc1037fx7ee727d8289ec495@mail.gmail.com> Message-ID: Hi James, I tried your test case and it works as expected for me; no stray "ix" or "sGroup" attributes. I believe here is what's happening: you have modified header files in libxsd to try to make Borland C++ work and use the same modified files with VC++ 2008 (but not Express). You said that you have recompiled the schemas but that is not enough. You need to make sure that the original, unmodified version of libxsd is used by VC++. Please double check that you have done this, and preferably remove the modified files altogether. Boris From jxmei3 at gmail.com Mon Oct 19 11:00:25 2009 From: jxmei3 at gmail.com (James Mei) Date: Mon Oct 19 11:00:36 2009 Subject: [xsd-users] Re: Help me: VC pro and VC express generate different XML In-Reply-To: References: <550334c10910160203y36735c65yf3776529cc365a84@mail.gmail.com> <550334c10910161710u68b1508fu83ed872e408cba2e@mail.gmail.com> <550334c10910161933t1cc1037fx7ee727d8289ec495@mail.gmail.com> Message-ID: <550334c10910190800k6405304fn952be8de1eef76b5@mail.gmail.com> Hi Boris Thanks for the reminder and suggestion. I have restored the containers.hxx and now VC++ express, VC++ pro, BCB 2009, BCB 2010 all works. Anything prior to (including) BCB2007 will have problems. I think the schemas that I am using is consider moderately complex. Even the xbinder, XML Data Binder (Borland) cannot generate a good working C++ code. I have tested XSD last year and it was giving problem on the same set of schemas. Now XSD is much better and providing a fully working and user friendly interface. Maybe you can do some testing on Borland 2009, 2010 compilers and add them to your supported list. Best regards James On Mon, Oct 19, 2009 at 10:11 PM, Boris Kolpackov wrote: > Hi James, > > I tried your test case and it works as expected for me; no stray "ix" > or "sGroup" attributes. > > I believe here is what's happening: you have modified header files in > libxsd to try to make Borland C++ work and use the same modified files > with VC++ 2008 (but not Express). You said that you have recompiled the > schemas but that is not enough. You need to make sure that the original, > unmodified version of libxsd is used by VC++. Please double check that > you have done this, and preferably remove the modified files altogether. > > Boris > > From boris at codesynthesis.com Mon Oct 19 11:13:50 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 19 11:07:43 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: <4ADAD958.4000905@kestrel.ws> References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> <4AD64A06.4070205@kestrel.ws> <4ADAD958.4000905@kestrel.ws> Message-ID: Hi Cerion, Cerion Armour-Brown writes: > Boris Kolpackov wrote: > > > If the stream ends with EOF then the parser assume there is no more > > data available. And if the document is incomplete, then you will get > > a parsing error. In your case, I guess, you will need to provide a > > custom std::istream implementation (or xercesc::InputSource -- that > > could actually be easier) that doesn't return on EOF but instead keeps > > polling the file for more data (e.g., you could save the offset of the > > last byte read, wait some time, re-open the file, seek to that saved > > offset, and see if there is more data). I assume you will need to > > implement this logic somewhere in the application in any case. With > > this approach it will just be in the stream. > > > > I had a look at doing this, but this I'm not happy about this direction. > Xerces buffers the file data, and if the buffer gets low, it reads > ahead. This means there may be data available to xerces (in its buffer), > but we're going to block on the file anyway. What actually happens is this: if the raw character buffer has less than 100 bytes when Xerces-C++ tries to transcode the next batch of characters, then it will try to read some more. There is actually a technical reason for this other than efficiency (it has to do with multi-byte encodings and the buffer containing only some of the bytes constituting a code point). Because Xerces-C++ won't keep trying to read more if the stream returned less than 100 bytes, one way to mitigate this would be to return the data from InputSource::readBytes() in small chunks. If you return it one byte at a time, there will be no buffering at all. > Plus I would need to take a look at the data last read from the file (i.e. > in xerces buffer, or seek back in the file), to see if EOF has been reached > correctly (closing tag has been read in). You mean you will need to check if "real" EOF has been reached, not the "fake" one ;-)? This is what happens when you try to "reuse" the same concept for different things. I wonder if there is better design for this? Can't you use a pipe or socket instead? > If I can avoid it, I'd prefer not to work with separate threads at all > (the above blocking read solution would need that). I imagined my Qt app > could be the driver, with a loop to pull in the next (few) top level > tags, and then update the GUI, and so on. This simplifies the whole > setup, and keeps Qt in control. Hm, that's hard to achieve. You want to pass the data and query the next construct. Something like this: parser p; p.here_is_more_data (buf, n); chunk c = p.give_me_next_construct (); The problem is that you may not pass enough data so there is no construct to return. While it is probably possible to implement an XML parser like this, it will complicate the design significantly since the parser must be prepared to stop parsing at any point, return control to the user and then resume parsing from that point again. > Qt solves this EOF problem by returning an UnexpectedEOF error, but make > this recoverable, so we can continue parsing. > > From what I understand from the docs and source code, XSD / Xerces don't > (yet) support recovery from this? No, and probably never will. I don't think such "EOF overloading" is a very common practice (or good design, for that matter). > If they do, how is this possible, and is this a way forward? I think the way forward would be to lower the chunk size returned by readBytes() as suggested above. If Qt must be in control, then I don't see any way to achieve this other than using a separate thread. I would also suggest that you use something other than a file to communicate the data between the two processes so that you don't need to play this real/fake EOF game. > P.S. Do you have plans to make a xml binder for the Qt parsers? ;-) We may implement the "Qt/Tree" mapping one day which will use the "Qt way of doing things", including XML parsers. But there are no immediate plans. Boris From jxmei3 at gmail.com Tue Oct 20 05:03:01 2009 From: jxmei3 at gmail.com (James Mei) Date: Tue Oct 20 05:03:08 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class Message-ID: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> Hi Boris After an xml file is parsed and populated into its designated class. I can create a TreeView out of it starting from the root. Also, I assigned the class pointer to TreeNode->Data for later manipulation. for (n = 0; n < sn.ConnectedAP().at(k).GSE().size(); n++) { TTreeNode *tn=spd->hTree->Items->AddChild(tn_gse, sn.ConnectedAP().at(k).GSE().at(n).cbName().c_str()); tn->Data = &sn.ConnectedAP().at(k).GSE().at(n).cbName(); tn=spd->hTree->Items->AddChild(tn_gse, sn.ConnectedAP().at(k).GSE().at(n).ldInst().c_str()); tn->Data = &sn.ConnectedAP().at(k).GSE().at(n).ldInst(); TTreeNode *tn_addr=spd->hTree->Items->AddChild(tn_gse, "Address"); for (m = 0; m < sn.ConnectedAP().at(k).GSE().at(n).Address().get().P().size(); m++) { tn=spd->hTree->Items->AddChild(tn_addr, sn.ConnectedAP().at(k).GSE().at(n).Address().get().P().at(m).type().c_str()); tn->Data=&sn.ConnectedAP().at(k).GSE().at(n).Address().get().P().at(m) } } Later when user click on the TreeNode, I can get the class pointer and start the appropriate operation with TreeNode->Data. However, I only have the pointer, not its class type. I do not know it is a pointer to GSE() or it is a pointer to Address() .... May I know how do I identify the type of this class pointer ? Also, is there a default data member in the generated class for storing reference data, such as the TreeNode->Data member. Regards James From boris at codesynthesis.com Tue Oct 20 09:30:05 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 20 09:24:09 2009 Subject: [xsd-users] Re: Help me: VC pro and VC express generate different XML In-Reply-To: <550334c10910190800k6405304fn952be8de1eef76b5@mail.gmail.com> References: <550334c10910160203y36735c65yf3776529cc365a84@mail.gmail.com> <550334c10910161710u68b1508fu83ed872e408cba2e@mail.gmail.com> <550334c10910161933t1cc1037fx7ee727d8289ec495@mail.gmail.com> <550334c10910190800k6405304fn952be8de1eef76b5@mail.gmail.com> Message-ID: Hi James, James Mei writes: > I have restored the containers.hxx and now VC++ express, VC++ pro, BCB 2009, > BCB 2010 all works. Anything prior to (including) BCB2007 will have > problems. Ok, thanks for the information. It is good to know BCB 2009 and 2010 work on a reasonably complex schema. > Maybe you can do some testing on Borland 2009, 2010 compilers and add > them to your supported list. Perhaps. At the moment there doesn't seem to be many people using or trying to use XSD with BCB. Boris From boris at codesynthesis.com Tue Oct 20 09:40:14 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 20 09:34:16 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> Message-ID: Hi James, James Mei writes: > Also, I assigned the class pointer to TreeNode->Data for later > manipulation. TreeNode->Data is of type void*, right? > However, I only have the pointer, not its class type. I do not know it > is a pointer to GSE() or it is a pointer to Address() May I know how do > I identify the type of this class pointer ? Assuming TreeNode->Data is void*, then you can cast it to xml_schema::type* and then use RTTI (dynamic_cast, typeid, etc.) to figure out its actual type. This will work because xml_schema::type is a base type for all generated and non-fundamental built-in types. For example: xml_schema::type* t = static_cast (TreeNode->Data); if (tGSE* gse = dynamic_cast (t)) { // Handle gse. } else if (tAddress* addr = dynamic_cast (t)) { // Handle addr. } ... > Also, is there a default data member in the generated class for storing > reference data, such as the TreeNode->Data member. No, there is no such pointer but you can add one by customizing the xml_schema::type type. For more information on how to do this, see the 'comments' example in the examples/cxx/tree/custom/ directory. Boris From boris at codesynthesis.com Tue Oct 20 10:08:36 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Tue Oct 20 10:02:43 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: <4ADC98E3.5040704@kestrel.ws> References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> <4AD64A06.4070205@kestrel.ws> <4ADAD958.4000905@kestrel.ws> <4ADC98E3.5040704@kestrel.ws> Message-ID: Hi Cerion, Cerion Armour-Brown writes: > I would _really_ have liked to use a file for debugging purposes: I > don't trust the XML source (Valgrind) not to mess things up, and I > wanted to allow users of my program to send me the XML file so I could > reproduce the error. You could "tee" the data to a file that the user could send you for debugging. It should also be pretty simple to "replay" such a file to a socket or pipe. I think I also figured out how to support the file approach. Your custom stream implementation would assume all EOFs are fake until notified otherwise. The SAX parser that builds the DOM chunks keeps track of the document depth. So you need to add a test in the endElement() function (after the depth is decreased, see parser.cxx in the example) for when you reach depth_ == 0. This means that the end tag has been seen. At this point you notify the stream to treat all further EOF as real. > What I did before with Qt3 was fairly straightforward: SAX reader, > callbacks on the end-tags to construct a DOM model. > The Qt SAX parser gives 'parse' and 'parseContinue' functions, which > keep track of the file position and buffer the XML data until it's > handed off via the end-tag callback. > All works well, and is simple. > Unfortunately, there's just no binding, so updates to the XML protocol > are horrible to maintain :-( Expat supports this API (parse/parseContinue) but it can only be used with C++/Parser in XSD. In XSD/e (XML data binding for mobile/embedded systems), however, there is the C++/Hybrid mapping which is basically an object model on top of the C++/Parser mapping. It also works with Expat (which is part of the XSD/e runtime library). So if you really want this parse/parseContinue approach then you can try C++/Hybrid. It supports partially event-driven, partially in-memory processing which will allow you to build and display the object model chunk by chunk (the streaming example for C++/Tree was in fact inspired by this). See the streaming example in the examples/cxx/hybrid/ directory of the XSD/e distribution for more information. Boris From erwann.houzay at ign.fr Tue Oct 20 11:18:27 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Tue Oct 20 12:56:15 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? Message-ID: <4ADDD4C3.9070100@ign.fr> Hi everybody; I use the following to produce a C++ libs for GML and CityGML: http://wiki.codesynthesis.com/Schemas/CityGML All is OK... (for code production) I've done the following C++ code: -------------------------------------------------------------------------- std::auto_ptr< ::citygml::CityModelType > model; try { model = citygml::CityModel("C:\\Users\\ehouzay\\Desktop\\waldbruecke_v1.0.0\\waldbruecke_v1.0.0.gml", ::xml_schema::flags::dont_validate); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } std::ofstream test_out("test.gml"); try { CityModel (test_out,*model.get()); //citygml::CityModel(test_out,model,::xml_schema::flags::dont_validate); } catch (const xml_schema::exception& e) { cerr << e << endl; return 1; } //Model description std::cout<description()<name().begin();itName!=model->name().end();itName++) std::cout<<"Name" <<(*itName)<boundedBy().get().Envelope().get(); //std::cout<::iterator it =LowerCorner.begin();it!=LowerCorner.end();it++) std::cout<<(*it)<featureMember().begin();itFeature!=model->featureMember().end();itFeature++) { ::gml::FeaturePropertyType feature = (*itFeature); ::gml::AbstractFeatureType FeatureType = feature._Feature().get(); } ... ----------------------- Here my sample inpuy file (from City GML web Site but reduced to get a very simple try): Written on 2009-02-05T06:14:44+01:00 by the CityGML exporter of the WB3 project http://www.wb3-project.de for CityGML Version 1.0. Usage, modification and storage of this data requires the consent of the WB3 project. All rights remain with the WB3 project or organizations named therein. This copyright notice is part of the data and may not be removed without explicit consent of the WB3 project. Waldbr?cke -648.04 -563.6 0 270.42 301.74 0 After reading, I output the file and I got: Written on 2009-02-05T06:14:44+01:00 by the CityGML exporter of the WB3 project http://www.wb3-project.de for CityGML Version 1.0. Usage, modification and storage of this data requires the consent of the WB3 project. All rights remain with the WB3 project or organizations named therein. This copyright notice is part of the data and may not be removed without explicit consent of the WB3 project. Waldbr?cke -648.04 -563.6 0 270.42 301.74 0 What had happen to the "cityObjectMember"? According to the CityGML doc (http://www.citygml.org/citygml/documentation/): CityModelType is "Type describing the "root" element of any city model file. It is a collection whose members are restricted to be features of a city model. All features are included as cityObjectMember. " CityModelType is AbstractFeatureCollectionType from gml and it seems not to be read correctly... (in fact sub CityGML sub element child of the cityObjectMember node seems not to be red correctly and constructors of those object are not called!!!) Is there a way to overcome this problem? I think it's a polymorphism pb.. I'm a newby so I have no idea of how to process... Any help will be usefull to overcome this difficulty... Tkanks Erwann From cerion at kestrel.ws Mon Oct 19 12:50:43 2009 From: cerion at kestrel.ws (Cerion Armour-Brown) Date: Tue Oct 20 12:57:16 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> <4AD64A06.4070205@kestrel.ws> <4ADAD958.4000905@kestrel.ws> Message-ID: <4ADC98E3.5040704@kestrel.ws> Hiya Boris, Boris Kolpackov wrote: >> Boris Kolpackov wrote >>> If the stream ends with EOF then the parser assume there is no more >>> data available. And if the document is incomplete, then you will get >>> a parsing error. In your case, I guess, you will need to provide a >>> custom std::istream implementation (or xercesc::InputSource -- that >>> could actually be easier) that doesn't return on EOF but instead keeps >>> polling the file for more data (e.g., you could save the offset of the >>> last byte read, wait some time, re-open the file, seek to that saved >>> offset, and see if there is more data). I assume you will need to >>> implement this logic somewhere in the application in any case. With >>> this approach it will just be in the stream. >>> >>> >> I had a look at doing this, but this I'm not happy about this direction. >> Xerces buffers the file data, and if the buffer gets low, it reads >> ahead. This means there may be data available to xerces (in its buffer), >> but we're going to block on the file anyway. >> > What actually happens is this: if the raw character buffer has less than > 100 bytes when Xerces-C++ tries to transcode the next batch of characters, > then it will try to read some more. There is actually a technical reason > for this other than efficiency (it has to do with multi-byte encodings > and the buffer containing only some of the bytes constituting a code > point). > Indeed. > Because Xerces-C++ won't keep trying to read more if the stream returned > less than 100 bytes, one way to mitigate this would be to return the data > from InputSource::readBytes() in small chunks. If you return it one byte > at a time, there will be no buffering at all. > Eugh - that's horrible! :-) >> Plus I would need to take a look at the data last read from the file (i.e. >> in xerces buffer, or seek back in the file), to see if EOF has been reached >> correctly (closing tag has been read in). >> > You mean you will need to check if "real" EOF has been reached, not the > "fake" one ;-)? This is what happens when you try to "reuse" the same > concept for different things. Exactly. > I wonder if there is better design for this? Can't you use a pipe or socket instead? > Moving to a pipe/socket might be the only way to go, indeed. I would _really_ have liked to use a file for debugging purposes: I don't trust the XML source (Valgrind) not to mess things up, and I wanted to allow users of my program to send me the XML file so I could reproduce the error. >> If I can avoid it, I'd prefer not to work with separate threads at all >> (the above blocking read solution would need that). I imagined my Qt app >> could be the driver, with a loop to pull in the next (few) top level >> tags, and then update the GUI, and so on. This simplifies the whole >> setup, and keeps Qt in control. >> > Hm, that's hard to achieve. You want to pass the data and query the next > construct. Something like this: > > parser p; > p.here_is_more_data (buf, n); > chunk c = p.give_me_next_construct (); > > The problem is that you may not pass enough data so there is no construct > to return. While it is probably possible to implement an XML parser like > this, it will complicate the design significantly since the parser must > be prepared to stop parsing at any point, return control to the user and > then resume parsing from that point again. > What I did before with Qt3 was fairly straightforward: SAX reader, callbacks on the end-tags to construct a DOM model. The Qt SAX parser gives 'parse' and 'parseContinue' functions, which keep track of the file position and buffer the XML data until it's handed off via the end-tag callback. All works well, and is simple. Unfortunately, there's just no binding, so updates to the XML protocol are horrible to maintain :-( >> Qt solves this EOF problem by returning an UnexpectedEOF error, but make >> this recoverable, so we can continue parsing. >> >> From what I understand from the docs and source code, XSD / Xerces don't >> (yet) support recovery from this? >> > No, and probably never will. I don't think such "EOF overloading" is a > very common practice (or good design, for that matter). > Fair enough, although I'm not sure you understand - Qt4 doesn't use EOF overloading: just as Xerces does, the parser throws the error, but it isn't _fatal_, and is easily recoverable from. One just needs to handle that EOF exception, wait for more data, and continue parsing. >> If they do, how is this possible, and is this a way forward? >> > I think the way forward would be to lower the chunk size returned by > readBytes() as suggested above. If Qt must be in control, then I don't > see any way to achieve this other than using a separate thread. > > I would also suggest that you use something other than a file to > communicate the data between the two processes so that you don't > need to play this real/fake EOF game. > Ok, I will ponder upon this a little more. >> P.S. Do you have plans to make a xml binder for the Qt parsers? ;-) >> > > We may implement the "Qt/Tree" mapping one day which will use the "Qt > way of doing things", including XML parsers. But there are no immediate > plans. > > Boris > Thanks Boris, Cerion From bpringle at sympatico.ca Tue Oct 20 15:38:55 2009 From: bpringle at sympatico.ca (Bill Pringlemeir) Date: Tue Oct 20 14:24:42 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: <4ADC98E3.5040704@kestrel.ws> (Cerion Armour-Brown's message of "Mon, 19 Oct 2009 18:50:43 +0200") References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> <4AD64A06.4070205@kestrel.ws> <4ADAD958.4000905@kestrel.ws> <4ADC98E3.5040704@kestrel.ws> Message-ID: <87aazl97ow.fsf@sympatico.ca> On 19 Oct 2009, cerion@kestrel.ws wrote: > What I did before with Qt3 was fairly straightforward: SAX reader, > callbacks on the end-tags to construct a DOM model. The Qt SAX > parser gives 'parse' and 'parseContinue' functions, which keep track > of the file position and buffer the XML data until it's handed off > via the end-tag callback. All works well, and is simple. > Unfortunately, there's just no binding, so updates to the XML > protocol are horrible to maintain :-( You can use a SAX parser (in Xerces as well) to parse available text. When a known top level chunk tag is recognized, it can then be passed to a normal XSD de-serializer. The overhead for SAX parsing of tags is fairly minimal. Also, if you have a partial buffer, you would have to keep the 'partial' XSD data model around to restart when more text was found. So having to keep the Valgrind text until SAX recognizes a completion tag isn't really the worst overhead. Having XSD (or whatever solution) keep the entire DOM tree, a data model, and possibly the text is definitely worse. The only objection I see is that XSD should provide a mode to not attempt to read further. I think you could provide your own stream and throw an exception if it reads beyond the known size. That should be a sanity check as opposed to a normal mode of operation. You might have to create some XML text that doesn't match the schema to test this. Fwiw, Bill Pringlemeir. From keith.c.wire at lmco.com Tue Oct 20 18:35:57 2009 From: keith.c.wire at lmco.com (Wire, Keith C) Date: Tue Oct 20 18:36:08 2009 Subject: [xsd-users] Preserve newline characters Message-ID: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> Hi, I have very large strings in my XML files. There are numerous newlines and tabs in the text itself to organize the data. It appears that when codesynthesis is parsing the xml the newlines are being removed. Is there any way to maintain them (I didn't see anything in the documentation)? Is this a codesynthesis issue or a Xerces-C issue? Thanks, Keith C Wire keith.c.wire@lmco.com From boris at codesynthesis.com Wed Oct 21 07:56:30 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 21 07:50:47 2009 Subject: [xsd-users] Preserve newline characters In-Reply-To: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> References: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> Message-ID: Hi Keith, Wire, Keith C writes: > I have very large strings in my XML files. There are numerous newlines > and tabs in the text itself to organize the data. It appears that when > codesynthesis is parsing the xml the newlines are being removed. Is there > any way to maintain them (I didn't see anything in the documentation)? > Is this a codesynthesis issue or a Xerces-C issue? Whitespace handling depends on the XML Schema type used for an element or attribute. xsd:string preserves all whitespaces. xsd:normalizedString performs whitespace normalization, that is, tabs, newlines, etc., are replaced with spaces. Then there is xsd:token which, besides performing normalization, also performs whitespace collapsing, that is, replacing all continuous spaces with a single space and removing leading and trailing whitespaces. So if you want to preserve all whitespaces in your text then you need to use xsd:string. Which type are you using? Boris From boris at codesynthesis.com Wed Oct 21 10:16:58 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 21 10:11:16 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: <4ADDD4C3.9070100@ign.fr> References: <4ADDD4C3.9070100@ign.fr> Message-ID: Hi Erwann, Erwann HOUZAY writes: > I use the following to produce a C++ libs for GML and CityGML: Do you put all the generated code into a single DLL or multiple DLLs? > > > What had happen to the "cityObjectMember"? This is actually quite tricky. Element cityObjectMember is of type gml:FeaturePropertyType and substitutes gml:featureMember. But gml:featureMember is also of gml:FeaturePropertyType. In other words, the substitution doesn't introduce a new type but just changes the element name. This doesn't not work well with XSD because during serialization the generated code uses object model types to automatically figure out which element name to use based on the substitution group information from the schemas. As a result, the generated code always uses featureMember since it has the same type as cityObjectModel. One way to overcome this in the C++/Tree mapping is to customize the xml_schema::type class (which is the base type for all the generated classes) by adding a custom element name and namespace members. This information is automatically extracted during parsing, can be queried and modified by the application, and is used during serialization to make sure the right element name is used. I have implemented this and uploaded a new version of the test driver for CityGML: http://wiki.codesynthesis.com/Schemas/CityGML With this change and with a small fix to your sample XML: Should be: The serialized XML is equivalent to the original. Let me know if this doesn't work for you. Boris From boris at codesynthesis.com Wed Oct 21 10:22:59 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 21 10:17:18 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> Message-ID: Hi James, In the future please keep your replies CC'ed to the xsd-users mailing list as discussed in the posting guidelines: http://www.codesynthesis.com/support/posting-guidelines.xhtml James Mei writes: > May I also know if the class contain the actual name of the element in > string form ? No. > I have tried > scl.get()->Header()._node()->getNodeName(), which > scl.get()->Header()._node() should be the *DOMNode, but it is NULL all the > time. Yes, you can do this but you will need to turn on DOM association during parsing. See Section 5.1, "DOM Association" in the C++/Tree Mapping User Manual for more information: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#5.1 Boris From jxmei3 at gmail.com Wed Oct 21 11:03:02 2009 From: jxmei3 at gmail.com (James Mei) Date: Wed Oct 21 11:03:10 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> Message-ID: <550334c10910210803g42eb0d71q37eea638cf991686@mail.gmail.com> Hi Boris Sorry I forgot this time. I was in a hurry. I will remember to cc to xsd-users. Thanks for the help, I will use xml_schema::flags::keep_dom to keep the DOM tree. Best regards James On Wed, Oct 21, 2009 at 10:22 PM, Boris Kolpackov wrote: > Hi James, > > In the future please keep your replies CC'ed to the xsd-users mailing > list as discussed in the posting guidelines: > > http://www.codesynthesis.com/support/posting-guidelines.xhtml > > > James Mei writes: > > > May I also know if the class contain the actual name of the element in > > string form ? > > No. > > > > I have tried > > scl.get()->Header()._node()->getNodeName(), which > > scl.get()->Header()._node() should be the *DOMNode, but it is NULL all > the > > time. > > Yes, you can do this but you will need to turn on DOM association during > parsing. See Section 5.1, "DOM Association" in the C++/Tree Mapping User > Manual for more information: > > > http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#5.1 > > Boris > From keith.c.wire at lmco.com Wed Oct 21 11:05:03 2009 From: keith.c.wire at lmco.com (Wire, Keith C) Date: Wed Oct 21 11:05:13 2009 Subject: [xsd-users] Preserve newline characters In-Reply-To: References: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> Message-ID: <382602E3CC137C4CBFF65B9CB0BF849F9DF899CC@HDXMSPA.us.lmco.com> I unfortunately do not get to control this schema, but they are using xsd:string. I used a debugger to look at the string as soon as the generated classes are used to extract the parsed data, as well as a print statement. Both show none of the newlines. I'm using XSD 3.2.0 and cxx-tree. Any ideas on what I could try would be appreciated. Thanks, Keith -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Wednesday, October 21, 2009 5:57 AM To: Wire, Keith C Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] Preserve newline characters Hi Keith, Wire, Keith C writes: > I have very large strings in my XML files. There are numerous > newlines and tabs in the text itself to organize the data. It appears > that when codesynthesis is parsing the xml the newlines are being > removed. Is there any way to maintain them (I didn't see anything in the documentation)? > Is this a codesynthesis issue or a Xerces-C issue? Whitespace handling depends on the XML Schema type used for an element or attribute. xsd:string preserves all whitespaces. xsd:normalizedString performs whitespace normalization, that is, tabs, newlines, etc., are replaced with spaces. Then there is xsd:token which, besides performing normalization, also performs whitespace collapsing, that is, replacing all continuous spaces with a single space and removing leading and trailing whitespaces. So if you want to preserve all whitespaces in your text then you need to use xsd:string. Which type are you using? Boris From boris at codesynthesis.com Wed Oct 21 11:21:37 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 21 11:15:54 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: <4ADF207E.6030505@ign.fr> References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> Message-ID: Hi Erwann, In the future please keep your replies CC'ed to the xsd-users mailing list as discussed in the posting guidelines: http://www.codesynthesis.com/support/posting-guidelines.xhtml Erwann HOUZAY writes: > Thank you for your help... > > I have built two separated static libs in VS 2003 (one for GML one for > CityGML) Ok, that should work. If you decide to convert them to DLLs, you will need to use the --export-maps and --import-maps options. > I think xml-schema.xsd is missing in your commit (in xs directory, > according to the make file)... Can you update it? No, xml-schema.xsd is a fake name, such file does not exist. When the --generate-xml-schema option is specified the file name is only used by the compiler to derive the C++ header name (e.g., xml-schema.xsd -> xml-schema.hxx, schema.xsd -> schema.hxx). The file doesn't need to exist but you can add an empty one if it makes it easier to build things (e.g., from VC++). > I will do test.s We are producing big CityGML files, it will be a good > test for you... Sounds good. Let me know if there are any problems. Boris From boris at codesynthesis.com Wed Oct 21 11:28:30 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 21 11:22:52 2009 Subject: [xsd-users] Preserve newline characters In-Reply-To: <382602E3CC137C4CBFF65B9CB0BF849F9DF899CC@HDXMSPA.us.lmco.com> References: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> <382602E3CC137C4CBFF65B9CB0BF849F9DF899CC@HDXMSPA.us.lmco.com> Message-ID: Hi Keith, Wire, Keith C writes: > I unfortunately do not get to control this schema, but they are using > xsd:string. Ok, it should be xsd:string so this is not a problem. > I used a debugger to look at the string as soon as the generated > classes are used to extract the parsed data, as well as a print > statement. Both show none of the newlines. Can you try building the hello example in the examples/cxx/tree/ directory and changing the greeting string in hello.xml to include some newlines and tabs. Then run the example on this file and see what you get? If I change: Hello to: Hello there tab I get this (expected) output: Hello there tab, sun! Hello there tab, moon! Hello there tab, world! > I'm using XSD 3.2.0 and cxx-tree. What platform and compiler are you using? Also what version of Xerces-C++? Boris From keith.c.wire at lmco.com Wed Oct 21 11:41:50 2009 From: keith.c.wire at lmco.com (Wire, Keith C) Date: Wed Oct 21 11:42:01 2009 Subject: [xsd-users] Preserve newline characters In-Reply-To: References: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> <382602E3CC137C4CBFF65B9CB0BF849F9DF899CC@HDXMSPA.us.lmco.com> Message-ID: <382602E3CC137C4CBFF65B9CB0BF849F9DF89B09@HDXMSPA.us.lmco.com> I tried the example as you asked an got the expected results. The newlines and tabs were reserved and printed. I am running on Solaris 10 Sparc. Compiler is the Solaris CC compiler. Xerces-C++ 2.8 Keith -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Wednesday, October 21, 2009 9:29 AM To: Wire, Keith C Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] Preserve newline characters Hi Keith, Wire, Keith C writes: > I unfortunately do not get to control this schema, but they are using > xsd:string. Ok, it should be xsd:string so this is not a problem. > I used a debugger to look at the string as soon as the generated > classes are used to extract the parsed data, as well as a print > statement. Both show none of the newlines. Can you try building the hello example in the examples/cxx/tree/ directory and changing the greeting string in hello.xml to include some newlines and tabs. Then run the example on this file and see what you get? If I change: Hello to: Hello there tab I get this (expected) output: Hello there tab, sun! Hello there tab, moon! Hello there tab, world! > I'm using XSD 3.2.0 and cxx-tree. What platform and compiler are you using? Also what version of Xerces-C++? Boris From boris at codesynthesis.com Wed Oct 21 12:14:59 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 21 12:09:16 2009 Subject: [xsd-users] Preserve newline characters In-Reply-To: <382602E3CC137C4CBFF65B9CB0BF849F9DF89B09@HDXMSPA.us.lmco.com> References: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> <382602E3CC137C4CBFF65B9CB0BF849F9DF899CC@HDXMSPA.us.lmco.com> <382602E3CC137C4CBFF65B9CB0BF849F9DF89B09@HDXMSPA.us.lmco.com> Message-ID: Hi Keith, Wire, Keith C writes: > I tried the example as you asked an got the expected results. The > newlines and tabs were reserved and printed. Hm, that's strange. Can you copy the text with newlines and tabs from your original document to hello.xml and see if you get them in the output? Can you also try the opposite, i.e., put the text from hello.xml into your document and see if newlines and tabs disappear? If it works as expected in hello.xml and doesn't work in your application, then there has got to be something special about either your schema or the way you parse XML. Will you be able to send (off list) a test case that reproduce this problem so that I can take a look? Boris From jxmei3 at gmail.com Thu Oct 22 00:08:31 2009 From: jxmei3 at gmail.com (James Mei) Date: Thu Oct 22 00:08:35 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: <550334c10910210803g42eb0d71q37eea638cf991686@mail.gmail.com> References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> <550334c10910210803g42eb0d71q37eea638cf991686@mail.gmail.com> Message-ID: <550334c10910212108t5bed73ffm89a00dc08408ad05@mail.gmail.com> Hi Boris The sample code below works with normal pointer to a class. But when it is a TreeNode->Data is "const sequence &", then the following code crashed. xml_schema::type* t = static_cast (TreeNode->Data); //<-- crash here if TreeNode->Data has "const sequence &" if (tGSE* gse = dynamic_cast (t)) { // Handle gse. } else if (tAddress* addr = dynamic_cast (t)) { // Handle addr. } Here is the code that assigning the TreeNode->Data pointer TTreeNode *tn_DS=spd->hTree->Items->AddChild(hParent, "Data Sets"); tn_DS->Data=&LD->LN0().DataSet(); //this is the "const sequence &" for (i = 0; i < LD->LN0().DataSet().size(); i++) { tn=spd->hTree->Items->AddChild(tn_DS, LD->LN0().DataSet().at(i).name().c_str()); tn->Data = &LD->LN0().DataSet().at(i); //it works fine } May I know how to tell the different between const sequence and ? Cheers James > On Wed, Oct 21, 2009 at 10:22 PM, Boris Kolpackov > wrote: > >> Hi James, >> >> In the future please keep your replies CC'ed to the xsd-users mailing >> list as discussed in the posting guidelines: >> >> http://www.codesynthesis.com/support/posting-guidelines.xhtml >> >> >> James Mei writes: >> >> > May I also know if the class contain the actual name of the element in >> > string form ? >> >> No. >> >> >> > I have tried >> > scl.get()->Header()._node()->getNodeName(), which >> > scl.get()->Header()._node() should be the *DOMNode, but it is NULL all >> the >> > time. >> >> Yes, you can do this but you will need to turn on DOM association during >> parsing. See Section 5.1, "DOM Association" in the C++/Tree Mapping User >> Manual for more information: >> >> >> http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#5.1 >> >> Boris >> > > From erwann.houzay at ign.fr Thu Oct 22 07:56:08 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Thu Oct 22 08:28:06 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> Message-ID: <4AE04858.5010200@ign.fr> Sorry for the liste ;-) I've tried your solution (well I have very few knowledge about codesynthesis, so I don't understand all...) Well, is works now but sub-element under cityObjectMember are not detected... I've tried the sample on cityGML website (http://www.citygml.org/1539/) and it doesn't work. cityObjectMember if exported correctly in the output file... Any idea? Thanks Boris Kolpackov a ?crit : > Hi Erwann, > > In the future please keep your replies CC'ed to the xsd-users mailing > list as discussed in the posting guidelines: > > http://www.codesynthesis.com/support/posting-guidelines.xhtml > > > Erwann HOUZAY writes: > > >> Thank you for your help... >> >> I have built two separated static libs in VS 2003 (one for GML one for >> CityGML) >> > > Ok, that should work. If you decide to convert them to DLLs, you will > need to use the --export-maps and --import-maps options. > > > >> I think xml-schema.xsd is missing in your commit (in xs directory, >> according to the make file)... Can you update it? >> > > No, xml-schema.xsd is a fake name, such file does not exist. When the > --generate-xml-schema option is specified the file name is only used > by the compiler to derive the C++ header name (e.g., xml-schema.xsd -> > xml-schema.hxx, schema.xsd -> schema.hxx). The file doesn't need to > exist but you can add an empty one if it makes it easier to build > things (e.g., from VC++). > > > >> I will do test.s We are producing big CityGML files, it will be a good >> test for you... >> > > Sounds good. Let me know if there are any problems. > > Boris > > From boris at codesynthesis.com Thu Oct 22 08:44:22 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 22 08:39:20 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: <550334c10910212108t5bed73ffm89a00dc08408ad05@mail.gmail.com> References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> <550334c10910210803g42eb0d71q37eea638cf991686@mail.gmail.com> <550334c10910212108t5bed73ffm89a00dc08408ad05@mail.gmail.com> Message-ID: Hi James, James Mei writes: > The sample code below works with normal pointer to a class. But when it is a > TreeNode->Data is "const sequence &", then the following code > crashed. sequence (and other containers) are not derived from xml_schema::type so this won't work. Only C++ classes corresponding to XML Schema types are derived from xml_schema::type. If you need to store a pointer to sequence then you will need to invent your own type information. Boris From boris at codesynthesis.com Thu Oct 22 09:15:40 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 22 09:10:17 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: <4AE04858.5010200@ign.fr> References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> Message-ID: Hi Erwann, Erwann HOUZAY writes: > I've tried your solution (well I have very few knowledge about > codesynthesis, so I don't understand all...) > > Well, is works now but sub-element under cityObjectMember are not > detected... > > I've tried the sample on cityGML website (http://www.citygml.org/1539/) > and it doesn't work. > > cityObjectMember if exported correctly in the output file... You mean that your application doesn't "see" them but they are in the output file, right? If that's the case then it is most likely because of the polymorphism. You need to figure out the actual element type and cast the pointer to it, for example: for(gml::AbstractFeatureCollectionType::featureMember_iterator itFeature=model->featureMember().begin(); itFeature!=model->featureMember().end(); itFeature++) { // Note the use of references! // gml::FeaturePropertyType& feature = (*itFeature); gml::AbstractFeatureType& af = feature._Feature().get(); if (CityObjectGroupType* cog = dynamic_cast (&af)) { // Handle cog. } else if (BuildingType* b = dynamic_cast (&af)) { // Handle building. } ... } See Section 2.11, "Mapping for xsi:type and Substitution Groups" in the C++/Tree Mapping User Manual for more information: http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.11 Boris From boris at codesynthesis.com Thu Oct 22 09:32:01 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 22 09:26:39 2009 Subject: [xsd-users] dealing with xml written/read on-the-fly In-Reply-To: <87aazl97ow.fsf@sympatico.ca> References: <4AD06CA1.5030602@kestrel.ws> <4AD574C6.4020503@kestrel.ws> <4AD64A06.4070205@kestrel.ws> <4ADAD958.4000905@kestrel.ws> <4ADC98E3.5040704@kestrel.ws> <87aazl97ow.fsf@sympatico.ca> Message-ID: Hi Bill, Bill Pringlemeir writes: > You can use a SAX parser (in Xerces as well) to parse available text. > When a known top level chunk tag is recognized, it can then be passed > to a normal XSD de-serializer. The overhead for SAX parsing of tags > is fairly minimal. Also, if you have a partial buffer, you would have > to keep the 'partial' XSD data model around to restart when more text > was found. So having to keep the Valgrind text until SAX recognizes a > completion tag isn't really the worst overhead. Having XSD (or > whatever solution) keep the entire DOM tree, a data model, and > possibly the text is definitely worse. > > The only objection I see is that XSD should provide a mode to not > attempt to read further. I think you could provide your own stream > and throw an exception if it reads beyond the known size. That should > be a sanity check as opposed to a normal mode of operation. You might > have to create some XML text that doesn't match the schema to test > this. The approach shown in the streaming example[1] is much better. It uses the little-known Xerces-C++ feature called progressive parsing. In this mode Xerces-C++ returns control to the caller after parsing one token in the XML document. The streaming example uses SAX2 in the progressive mode to build and return one DOM chunk corresponding to one second level element at a time. This DOM fragment is then parsed in to the object model fragment and can be processed and discarded or added to the object model. [1] http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-streaming.tar.gz http://www.codesynthesis.com/~boris/tmp/xsd-3.2.0-streaming.zip Boris From erwann.houzay at ign.fr Thu Oct 22 09:36:16 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Thu Oct 22 10:08:03 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> Message-ID: <4AE05FD0.4010207@ign.fr> Data are not correcly written. I looked also inside the C++ object through Visual debugger (very helpful..) and the object associated to the cityObjectMemeber seems to contain nothing... I'm doing my tests using the first dataset available on the ressource data page of the CityGML website... The input is looking like this Geb?ude und Freifl?che Wohnen(1300) g_12529 2009-01-11 WB3 Project http://www.wb3-project.de/wb_g_id.html?db=waldbruecke&id=12529 etc.... The output Child node are not decoded ("constructors" are not even called) I follow the Makefile and translate it to use it with Visual without any change... Maybe it's not enough or there's a side effect... Thank you for your help... Boris Kolpackov a ?crit : > Hi Erwann, > > Erwann HOUZAY writes: > > >> I've tried your solution (well I have very few knowledge about >> codesynthesis, so I don't understand all...) >> >> Well, is works now but sub-element under cityObjectMember are not >> detected... >> >> I've tried the sample on cityGML website (http://www.citygml.org/1539/) >> and it doesn't work. >> >> cityObjectMember if exported correctly in the output file... >> > > You mean that your application doesn't "see" them but they are in the > output file, right? If that's the case then it is most likely because > of the polymorphism. You need to figure out the actual element type > and cast the pointer to it, for example: > > for(gml::AbstractFeatureCollectionType::featureMember_iterator > itFeature=model->featureMember().begin(); > itFeature!=model->featureMember().end(); > itFeature++) > { > // Note the use of references! > // > gml::FeaturePropertyType& feature = (*itFeature); > gml::AbstractFeatureType& af = feature._Feature().get(); > > if (CityObjectGroupType* cog = dynamic_cast (&af)) > { > // Handle cog. > } > else if (BuildingType* b = dynamic_cast (&af)) > { > // Handle building. > } > > ... > } > > See Section 2.11, "Mapping for xsi:type and Substitution Groups" in the > C++/Tree Mapping User Manual for more information: > > http://www.codesynthesis.com/projects/xsd/documentation/cxx/tree/manual/#2.11 > > Boris > > From boris at codesynthesis.com Thu Oct 22 10:17:51 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 22 10:22:06 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: <4AE05FD0.4010207@ign.fr> References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> Message-ID: Hi Erwann, Erwann HOUZAY writes: > I'm doing my tests using the first dataset available on the ressource > data page of the CityGML website... I tried it (waldbruecke_v1.0.0.gml) and the output looks good. I see CityObjectGroup elements inside cityObjectMember. I don't know if you are using original driver.cxx or your own code to test this. Can you try it with driver.cxx (validation enabled) and see if it works for you? Boris From erwann.houzay at ign.fr Thu Oct 22 11:36:33 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Thu Oct 22 11:39:07 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> Message-ID: <4AE07C01.7080505@ign.fr> Ok... I've done this without validation. Validation doesn't work: unable to connect to the xsd... Is the socket configuration care about trhe system proxy configuration under windows? Boris Kolpackov a ?crit : > Hi Erwann, > > Erwann HOUZAY writes: > > >> I'm doing my tests using the first dataset available on the ressource >> data page of the CityGML website... >> > > I tried it (waldbruecke_v1.0.0.gml) and the output looks good. I see > CityObjectGroup elements inside cityObjectMember. I don't know if you > are using original driver.cxx or your own code to test this. Can you > try it with driver.cxx (validation enabled) and see if it works for > you? > > Boris > > From boris at codesynthesis.com Thu Oct 22 11:50:10 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 22 11:44:40 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: <4AE07C01.7080505@ign.fr> References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> <4AE07C01.7080505@ign.fr> Message-ID: Hi Erwann, Erwann HOUZAY writes: > Validation doesn't work: unable to connect to the xsd... You can change the XML file (as well as the CityGML schemas) to use the local copies of the GML and CityGML schemas. Or, you can preload them before parsing (see the 'caching' example in the examples/cxx/tree/ directory) in which case the remote URLs will be ignored. > Is the socket configuration care about trhe system proxy configuration > under windows? Hm, I am not sure about that. You will need to check the Xerces-C++ documentation. Boris From keith.c.wire at lmco.com Thu Oct 22 12:13:53 2009 From: keith.c.wire at lmco.com (Wire, Keith C) Date: Thu Oct 22 12:14:07 2009 Subject: [xsd-users] Preserve newline characters In-Reply-To: References: <382602E3CC137C4CBFF65B9CB0BF849F9DF892A6@HDXMSPA.us.lmco.com> <382602E3CC137C4CBFF65B9CB0BF849F9DF899CC@HDXMSPA.us.lmco.com> <382602E3CC137C4CBFF65B9CB0BF849F9DF89B09@HDXMSPA.us.lmco.com> Message-ID: <382602E3CC137C4CBFF65B9CB0BF849F9E0DB07B@HDXMSPA.us.lmco.com> Well we found the issue. When extracting the data we were using fstream which by default was skipping the whitespaces. We set it to not skip (noskipws) and everything works as expected. Thanks for helping us look in more directions to find the solution. Keith -----Original Message----- From: Boris Kolpackov [mailto:boris@codesynthesis.com] Sent: Wednesday, October 21, 2009 10:15 AM To: Wire, Keith C Cc: xsd-users@codesynthesis.com Subject: Re: [xsd-users] Preserve newline characters Hi Keith, Wire, Keith C writes: > I tried the example as you asked an got the expected results. The > newlines and tabs were reserved and printed. Hm, that's strange. Can you copy the text with newlines and tabs from your original document to hello.xml and see if you get them in the output? Can you also try the opposite, i.e., put the text from hello.xml into your document and see if newlines and tabs disappear? If it works as expected in hello.xml and doesn't work in your application, then there has got to be something special about either your schema or the way you parse XML. Will you be able to send (off list) a test case that reproduce this problem so that I can take a look? Boris From erwann.houzay at ign.fr Thu Oct 22 12:30:18 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Thu Oct 22 15:43:24 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: References: <4ADDD4C3.9070100@ign.fr> <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> <4AE07C01.7080505@ign.fr> Message-ID: <4AE0889A.6020500@ign.fr> I'm trying file caching but caching CityGML is not easy at all due to cross calls to the various GML schemes... Seems to need a few work to make it work... For Xerces and proxy, well some googling show me that it's a simple net accessor implemented in Xerces. Some modification may exist to pick out the IE settings under Windows... I'm not an expert, so I will try a local cache... Boris Kolpackov a ?crit : > Hi Erwann, > > Erwann HOUZAY writes: > > > >> Validation doesn't work: unable to connect to the xsd... >> > > You can change the XML file (as well as the CityGML schemas) to use the > local copies of the GML and CityGML schemas. Or, you can preload them > before parsing (see the 'caching' example in the examples/cxx/tree/ > directory) in which case the remote URLs will be ignored. > > > >> Is the socket configuration care about trhe system proxy configuration >> under windows? >> > > Hm, I am not sure about that. You will need to check the Xerces-C++ > documentation. > > Boris > > > From boris at codesynthesis.com Thu Oct 22 15:50:57 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 22 15:45:33 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: <4AE0889A.6020500@ign.fr> References: <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> <4AE07C01.7080505@ign.fr> <4AE0889A.6020500@ign.fr> Message-ID: Hi Erwann, Erwann HOUZAY writes: > I'm trying file caching but caching CityGML is not easy at all due to > cross calls to the various GML schemes... Seems to need a few work to > make it work... Here is the modified test driver that pre-loads all the GML and CityGML schemas before parsing: http://www.codesynthesis.com/~boris/tmp/citygml-driver-caching.cxx Works for me with network cable unplugged. Boris From jxmei3 at gmail.com Fri Oct 23 04:50:10 2009 From: jxmei3 at gmail.com (James Mei) Date: Fri Oct 23 04:50:18 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> <550334c10910210803g42eb0d71q37eea638cf991686@mail.gmail.com> <550334c10910212108t5bed73ffm89a00dc08408ad05@mail.gmail.com> Message-ID: <550334c10910230150m7499b9a7g966954202e213ef4@mail.gmail.com> Hi Boris May I know how to get the text value of the Enum from the generated class ? With the following class, I want to get GSSE and GOOSE as text. class tGSEControlTypeEnum: public ::xml_schema::name { public: enum value { GSSE, GOOSE }; tGSEControlTypeEnum (value v); tGSEControlTypeEnum (const char* v); tGSEControlTypeEnum (const ::std::string& v); tGSEControlTypeEnum (const ::xml_schema::name& v); ....... } Regards James On Thu, Oct 22, 2009 at 8:44 PM, Boris Kolpackov wrote: > Hi James, > > James Mei writes: > > > The sample code below works with normal pointer to a class. But when it > is a > > TreeNode->Data is "const sequence &", then the following code > > crashed. > > sequence (and other containers) are not derived from xml_schema::type so > this won't work. Only C++ classes corresponding to XML Schema types are > derived from xml_schema::type. If you need to store a pointer to sequence > then you will need to invent your own type information. > > Boris > From jxmei3 at gmail.com Fri Oct 23 06:03:06 2009 From: jxmei3 at gmail.com (James Mei) Date: Fri Oct 23 06:03:14 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: <550334c10910230150m7499b9a7g966954202e213ef4@mail.gmail.com> References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> <550334c10910210803g42eb0d71q37eea638cf991686@mail.gmail.com> <550334c10910212108t5bed73ffm89a00dc08408ad05@mail.gmail.com> <550334c10910230150m7499b9a7g966954202e213ef4@mail.gmail.com> Message-ID: <550334c10910230303n7e5c0ccfv167f7d6c1e92c02f@mail.gmail.com> Hi Boris I found the reference for the name: gsec->type()._xsd_tGSEControlTypeEnum_literals_[2] But is there any variable stores the number of values in the enum ? in this case it is 2. Regards James On Fri, Oct 23, 2009 at 4:50 PM, James Mei wrote: > Hi Boris > > May I know how to get the text value of the Enum from the generated class ? > With the following class, I want to get GSSE and GOOSE as text. > > class tGSEControlTypeEnum: public ::xml_schema::name > { > public: > enum value > { > GSSE, > GOOSE > }; > > tGSEControlTypeEnum (value v); > > tGSEControlTypeEnum (const char* v); > > tGSEControlTypeEnum (const ::std::string& v); > > tGSEControlTypeEnum (const ::xml_schema::name& v); > > ....... > } > > Regards > James > > > On Thu, Oct 22, 2009 at 8:44 PM, Boris Kolpackov wrote: > >> Hi James, >> >> James Mei writes: >> >> > The sample code below works with normal pointer to a class. But when it >> is a >> > TreeNode->Data is "const sequence &", then the following code >> > crashed. >> >> sequence (and other containers) are not derived from xml_schema::type so >> this won't work. Only C++ classes corresponding to XML Schema types are >> derived from xml_schema::type. If you need to store a pointer to sequence >> then you will need to invent your own type information. >> >> Boris >> > > From erwann.houzay at ign.fr Fri Oct 23 06:07:53 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Fri Oct 23 09:34:07 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: References: <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> <4AE07C01.7080505@ign.fr> <4AE0889A.6020500@ign.fr> Message-ID: <4AE18079.8080601@ign.fr> I'm sorry... I don't understand... You can dowload my visual project here ftp://ftp.ign.fr/ign/depot/Citygml-1.0.0.zip It compiles only in debug mode... I still don't have all the child nodes.... What is hapenning??? I have really no idea.... Thanks again for your help... Boris Kolpackov a ?crit : > Hi Erwann, > > Erwann HOUZAY writes: > > >> I'm trying file caching but caching CityGML is not easy at all due to >> cross calls to the various GML schemes... Seems to need a few work to >> make it work... >> > > Here is the modified test driver that pre-loads all the GML and CityGML > schemas before parsing: > > http://www.codesynthesis.com/~boris/tmp/citygml-driver-caching.cxx > > Works for me with network cable unplugged. > > Boris > > From boris at codesynthesis.com Fri Oct 23 10:37:06 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Oct 23 10:31:53 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: <4AE18079.8080601@ign.fr> References: <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> <4AE07C01.7080505@ign.fr> <4AE0889A.6020500@ign.fr> <4AE18079.8080601@ign.fr> Message-ID: Hi Erwann, Erwann HOUZAY writes: > I still don't have all the child nodes. Ok, here is what's going on: you are compiling GML and CityGML schemas into static libraries but static linking is tricky in that only object files with symbols that are referenced from the executable are added. Files that are not directly referenced are ignored. In your case, files that define polymorphic derived types in the CityGML schemas but which are not directly used by the test driver are not added to the executable. As a result, they are not available during parsing. I created a single executable project with all the source code and without any libraries and it works as expected. You can use DLLs since they don't have this issue. I see you tried to use the --export-maps option but you did it incorrectly. You need to compile GML schemas with --export-maps and CityGML schemas with --import-maps. See the compiler documentation for more information on these options. Also, place xml-schema-custom.cxx into gml.dll. Boris From erwann.houzay at ign.fr Fri Oct 23 10:20:52 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Fri Oct 23 10:32:10 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: References: <4ADF207E.6030505@ign.fr> <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> <4AE07C01.7080505@ign.fr> <4AE0889A.6020500@ign.fr> Message-ID: <4AE1BBC4.6030400@ign.fr> Ok, solved my problem.... I put all the file in the same VS project and it works... As you have mentionned it before, I need to play with the --import-map and --export-map option to find the good trick... I've splitted the code in various libs and transversal definition was not fowareded and explains the strange things I got. I confirm that it works under Linux. Good job!!! Thanks a lot and sorry I'm a newbie... Boris Kolpackov a ?crit : > Hi Erwann, > > Erwann HOUZAY writes: > > >> I'm trying file caching but caching CityGML is not easy at all due to >> cross calls to the various GML schemes... Seems to need a few work to >> make it work... >> > > Here is the modified test driver that pre-loads all the GML and CityGML > schemas before parsing: > > http://www.codesynthesis.com/~boris/tmp/citygml-driver-caching.cxx > > Works for me with network cable unplugged. > > Boris > > From boris at codesynthesis.com Fri Oct 23 10:44:34 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Oct 23 10:39:23 2009 Subject: [xsd-users] Help me: How to find out what is the type of a class In-Reply-To: <550334c10910230150m7499b9a7g966954202e213ef4@mail.gmail.com> References: <550334c10910200203l7fd6dd90j3acd23dffff37199@mail.gmail.com> <550334c10910210626k1faf5a10nfaae5d039aec202@mail.gmail.com> <550334c10910210803g42eb0d71q37eea638cf991686@mail.gmail.com> <550334c10910212108t5bed73ffm89a00dc08408ad05@mail.gmail.com> <550334c10910230150m7499b9a7g966954202e213ef4@mail.gmail.com> Message-ID: <20091023144434.GA24860@onega.codesynthesis.com> Hi James, Message-ID: James Mei writes: > May I know how to get the text value of the Enum from the generated class ? > With the following class, I want to get GSSE and GOOSE as text. > > class tGSEControlTypeEnum: public ::xml_schema::name > { > public: > enum value > { > GSSE, > GOOSE > }; Since tGSEControlTypeEnum is derived from xml_schema::name which in turn is derived from std::string, you can do it like this: tGSEControlTypeEnum x (tGSEControlTypeEnum::GOOSE); std::string& str = x; You can also user the enum object directly where std::string is expected or can be used, for example: cerr << x; const char* s = x.c_str (); > ... is there any variable stores the number of values in the enum ? in > this case it is 2. No, there is no such variable. The last enumerator's value + 1 is the total number of enumerators, though its name is not regular. Boris From erwann.houzay at ign.fr Fri Oct 23 10:52:18 2009 From: erwann.houzay at ign.fr (Erwann HOUZAY) Date: Fri Oct 23 14:04:15 2009 Subject: [xsd-users] Some difficulties with GML/CityGML Tree Parser generation : a bug? In-Reply-To: References: <4AE04858.5010200@ign.fr> <4AE05FD0.4010207@ign.fr> <4AE07C01.7080505@ign.fr> <4AE0889A.6020500@ign.fr> <4AE18079.8080601@ign.fr> Message-ID: <4AE1C322.1040400@ign.fr> Yep I need a while to understand the pb source... Thanks for the import-map and export-map combinaison options... Could you had those informations in the wiki page associated to CityGML? It's interessting... I also suggest to place the sample cache driver inside the files... It's very usefull... Maybe you can advise the mainnteners of the CityGML.org website that your tool work pretty well... There's no other free libs in C++ that can load/write those files... It's also tested under Linux (Ubuntu) Thanks again and good job!!! Erwann Boris Kolpackov a ?crit : > Hi Erwann, > > Erwann HOUZAY writes: > > >> I still don't have all the child nodes. >> > > Ok, here is what's going on: you are compiling GML and CityGML schemas > into static libraries but static linking is tricky in that only object > files with symbols that are referenced from the executable are added. > Files that are not directly referenced are ignored. In your case, files > that define polymorphic derived types in the CityGML schemas but which > are not directly used by the test driver are not added to the executable. > As a result, they are not available during parsing. I created a single > executable project with all the source code and without any libraries > and it works as expected. > > You can use DLLs since they don't have this issue. I see you tried to > use the --export-maps option but you did it incorrectly. You need to > compile GML schemas with --export-maps and CityGML schemas with > --import-maps. See the compiler documentation for more information > on these options. Also, place xml-schema-custom.cxx into gml.dll. > > Boris > > > > > > > From jxmei3 at gmail.com Fri Oct 23 20:46:15 2009 From: jxmei3 at gmail.com (James Mei) Date: Fri Oct 23 20:46:18 2009 Subject: [xsd-users] Help me: XMemory::~XMemory not found in .NET application Message-ID: <550334c10910231746jaf54038j7733830e2ffdd7ee@mail.gmail.com> Hi Boris This might be xercesc problem on .NET. When I try to use the generated cxx and hxx files in a .NET application (XSD works with pure Win32 VC application and Xercesc lib), the linker complains with lots of this message in each of the obj file compiled from cxx. I have included the xerces-c_3D.lib for debug build, but seems the lib does not contain the destruction member of XMemroy. Error 26765 error LNK2020: unresolved token (0A00001F) "protected: virtual __clrcall xercesc_3_0::XMemory::~XMemory(void)" (??1XMemory@xercesc_3_0@@$$FMAM@XZ) SCL_Substation.obj Cheers James From boris at codesynthesis.com Mon Oct 26 09:17:52 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 26 09:13:21 2009 Subject: [xsd-users] Re: Help me: XMemory::~XMemory not found in .NET application In-Reply-To: <550334c10910231746jaf54038j7733830e2ffdd7ee@mail.gmail.com> References: <550334c10910231746jaf54038j7733830e2ffdd7ee@mail.gmail.com> Message-ID: Hi James, James Mei writes: > When I try to use the generated cxx and hxx files in a .NET application (XSD > works with pure Win32 VC application and Xercesc lib), the linker complains > with lots of this message in each of the obj file compiled from cxx. I have > included the xerces-c_3D.lib for debug build, but seems the lib does not > contain the destruction member of XMemroy. Fist of all, we only support standard C++ when it comes to XSD. We don't have any experience with using XSD in .NET managed applications. Having said that, I think the problem is quite obvious: you are trying to link a native C++ library (Xerces-C++) to a managed application. I would think this won't work. If you decide to try to build Xerces-C++ as a managed library and run into problems, please seek help on the Xerces-C++ mailing lists: http://xerces.apache.org/xerces-c/mailing-lists.html Boris From jxmei3 at gmail.com Wed Oct 28 04:32:38 2009 From: jxmei3 at gmail.com (James Mei) Date: Wed Oct 28 04:32:48 2009 Subject: [xsd-users] Help me: Access Violation on optional element during serialization Message-ID: <550334c10910280132r1625cc8bya437f12b136f0f2e@mail.gmail.com> Hi Boris I have tried MS VC++ express, Pro and Borland BCB2007, 2009, 2010 compilers on XSD generated files. Other than BCB2007, other compiler works to certain extends. MS VC++ express and Pro works with no problem. The down side is that it only works on Win32, not .NET (or Xerces works on Win32 only). In this case, it limits the number of GUI controls I can put in. It would be difficult to program if it needs a big "case WM_COMMAND" instead of the .NET GUI event driven API. BCB2007: It requires the container.hxx to be modified to allow the program to be compiled. But after that, no attributes are output. BCB2009 and BCB2010: (The advantages of BCB2009/BCB2010 is that the GUI is Win32 based with event driven API. Similar to .NET and works with XSD. ) No files need to be modified. Most XML parse correctly and output correctly, except some "optional" elements. With the above example schema: SCL->Communication->SubNetwork->BitRate SCL->Communication->SubNetwork->ConnectedAP->GSE->MinTime SCL->Communication->SubNetwork->ConnectedAP->GSE->MaxTime ..... The above elements are optional. If the elements do not exist in the xml file or I "reset()" the pointer (delete it), XSD works perfectly. If they are presented in the xml file, the parser and data structure works correctly. I can display all the members of the those optional class. However, when I pass the *SCL to the serialization function, "access violation" on the following code in string.txx template XMLCh* char_transcoder:: from (const C* s, std::size_t len) { bool valid (true); const C* end (s + len); // Find what the resulting buffer size will be. // std::size_t rl (0); unsigned int count (0); for (const C* p (s); p < end; ++p) { unsigned char c (*p); //<--------access violation if (c < 0x80) { // Fast path. // rl += 1; continue; } else if ((c >> 5) == 0x06) count = 2; else if ((c >> 4) == 0x0E) count = 3; else if ((c >> 3) == 0x1E) count = 4; else { valid = false; break; } p += count - 1; // One will be added in the for loop if (p + 1 > end) { valid = false; break; } // BMP is represented by up to 3 code points in UTF-8. // rl += count > 3 ? 2 : 1; } Thanks for your help again. Cheers James -------------- next part -------------- A non-text attachment was scrubbed... Name: SCL.zip Type: application/zip Size: 24318 bytes Desc: not available Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20091028/661c765e/SCL.zip From jxmei3 at gmail.com Wed Oct 28 04:36:45 2009 From: jxmei3 at gmail.com (James Mei) Date: Wed Oct 28 04:36:52 2009 Subject: [xsd-users] Help me: Access Violation on optional element during serialization In-Reply-To: <550334c10910280132r1625cc8bya437f12b136f0f2e@mail.gmail.com> References: <550334c10910280132r1625cc8bya437f12b136f0f2e@mail.gmail.com> Message-ID: <550334c10910280136s630fa919v363ddc7ed294c102@mail.gmail.com> Hi Boris I have tried MS VC++ express, Pro and Borland BCB2007, 2009, 2010 compilers on XSD generated files. Other than BCB2007, other compiler works to certain extends. MS VC++ express and Pro works with no problem. The down side is that it only works on Win32, not .NET (or Xerces works on Win32 only). In this case, it limits the number of GUI controls I can put in. It would be difficult to program if it needs a big "case WM_COMMAND" instead of the .NET GUI event driven API. BCB2007: It requires the container.hxx to be modified to allow the program to be compiled. But after that, no attributes are output. BCB2009 and BCB2010: (The advantages of BCB2009/BCB2010 is that the GUI is Win32 based with event driven API. Similar to .NET and works with XSD. ) No files need to be modified. Most XML parse correctly and output correctly, except some "optional" elements. With the above example schema: SCL->Communication->SubNetwork->BitRate SCL->Communication->SubNetwork->ConnectedAP->GSE->MinTime SCL->Communication->SubNetwork->ConnectedAP->GSE->MaxTime ..... The above elements are optional. If the elements do not exist in the xml file or I "reset()" the pointer (delete it), XSD works perfectly. If they are presented in the xml file, the parser and data structure works correctly. I can display all the members of the those optional class. However, when I pass the *SCL to the serialization function, "access violation" on the following code in string.txx template XMLCh* char_transcoder:: from (const C* s, std::size_t len) { bool valid (true); const C* end (s + len); // Find what the resulting buffer size will be. // std::size_t rl (0); unsigned int count (0); for (const C* p (s); p < end; ++p) { unsigned char c (*p); //<--------access violation if (c < 0x80) { // Fast path. // rl += 1; continue; } else if ((c >> 5) == 0x06) count = 2; else if ((c >> 4) == 0x0E) count = 3; else if ((c >> 3) == 0x1E) count = 4; else { valid = false; break; } p += count - 1; // One will be added in the for loop if (p + 1 > end) { valid = false; break; } // BMP is represented by up to 3 code points in UTF-8. // rl += count > 3 ? 2 : 1; } Thanks for your help again. Cheers James -------------- next part -------------- A non-text attachment was scrubbed... Name: SCL.zip Type: application/zip Size: 24318 bytes Desc: not available Url : http://codesynthesis.com/pipermail/xsd-users/attachments/20091028/8bdac8aa/SCL-0001.zip From jxmei3 at gmail.com Wed Oct 28 04:49:26 2009 From: jxmei3 at gmail.com (James Mei) Date: Wed Oct 28 04:49:34 2009 Subject: [xsd-users] Re: Help me: Access Violation on optional element during serialization In-Reply-To: <550334c10910280136s630fa919v363ddc7ed294c102@mail.gmail.com> References: <550334c10910280132r1625cc8bya437f12b136f0f2e@mail.gmail.com> <550334c10910280136s630fa919v363ddc7ed294c102@mail.gmail.com> Message-ID: <550334c10910280149y604d8b10ve8f3647f3341c383@mail.gmail.com> Hi Boris When I trace in the code, it turns out that #ifndef XSD_USE_LCP // Convert UTF-8 to UTF-16 // return bits::char_transcoder::from ( //<------- s is NULL, but s.length() returns 19677280 (it might be the pointer to the string) s.c_str (), s.length ()); #else // Use Xerces-C++ local code page transcoding. // std_memory_manager mm; return xercesc::XMLString::transcode (s.c_str (), &mm); #endif On 10/28/09, James Mei wrote: > Hi Boris > > I have tried MS VC++ express, Pro and Borland BCB2007, 2009, 2010 > compilers on XSD generated files. Other than BCB2007, other compiler > works to certain extends. > > MS VC++ express and Pro works with no problem. The down side is that > it only works on Win32, not .NET (or Xerces works on Win32 only). In > this case, it limits the number of GUI controls I can put in. It would > be difficult to program if it needs a big "case WM_COMMAND" instead of > the .NET GUI event driven API. > > BCB2007: It requires the container.hxx to be modified to allow the > program to be compiled. But after that, no attributes are output. > > BCB2009 and BCB2010: (The advantages of BCB2009/BCB2010 is that the > GUI is Win32 based with event driven API. Similar to .NET and works > with XSD. ) > > No files need to be modified. Most XML parse correctly and output > correctly, except some "optional" elements. With the above example > schema: > > SCL->Communication->SubNetwork->BitRate > SCL->Communication->SubNetwork->ConnectedAP->GSE->MinTime > SCL->Communication->SubNetwork->ConnectedAP->GSE->MaxTime > ..... > The above elements are optional. If the elements do not exist in the > xml file or I "reset()" the pointer (delete it), XSD works perfectly. > If they are presented in the xml file, the parser and data structure > works correctly. I can display all the members of the those optional > class. However, when I pass the *SCL to the serialization function, > "access violation" on the following code in string.txx > > template > XMLCh* char_transcoder:: > from (const C* s, std::size_t len) > { > bool valid (true); > const C* end (s + len); > > // Find what the resulting buffer size will be. > // > std::size_t rl (0); > unsigned int count (0); > > for (const C* p (s); p < end; ++p) > { > unsigned char c (*p); > //<--------access violation > > if (c < 0x80) > { > // Fast path. > // > rl += 1; > continue; > } > else if ((c >> 5) == 0x06) > count = 2; > else if ((c >> 4) == 0x0E) > count = 3; > else if ((c >> 3) == 0x1E) > count = 4; > else > { > valid = false; > break; > } > > p += count - 1; // One will be added in the for loop > > if (p + 1 > end) > { > valid = false; > break; > } > > // BMP is represented by up to 3 code points in UTF-8. > // > rl += count > 3 ? 2 : 1; > } > > Thanks for your help again. > > Cheers > James > From boris at codesynthesis.com Wed Oct 28 10:34:32 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Wed Oct 28 10:30:23 2009 Subject: [xsd-users] Help me: Access Violation on optional element during serialization In-Reply-To: <550334c10910280136s630fa919v363ddc7ed294c102@mail.gmail.com> References: <550334c10910280132r1625cc8bya437f12b136f0f2e@mail.gmail.com> <550334c10910280136s630fa919v363ddc7ed294c102@mail.gmail.com> Message-ID: Hi James, James Mei writes: > The above elements are optional. If the elements do not exist in the > xml file or I "reset()" the pointer (delete it), XSD works perfectly. > If they are presented in the xml file, the parser and data structure > works correctly. I can display all the members of the those optional > class. However, when I pass the *SCL to the serialization function, > "access violation" on the following code in string.txx Which compiler is that, BCB or VC++? Are you using modified container.hxx? If you are using BCB or have modified XSD, I am afraid I won't be able to help you with this. Boris From boris at codesynthesis.com Thu Oct 29 04:30:02 2009 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Oct 29 04:26:04 2009 Subject: [xsd-users] [ANN] CLI command line interface compiler for C++ Message-ID: I would to announce a little side project of mine that some of you may find useful: CLI is an open-source (MIT license), cross-platform command line interface compiler for C++. It allows you to specify the options that your program supports, their types, and default values. For example: include ; class options { bool --help; std::string --name = "example"; unsigned int --level | -l = 5; }; This specification can then be automatically translated to C++ classes that implement parsing of the command line arguments and provide a convenient and type-safe interface for accessing the extracted data. For example: #include class options { public: options (int argc, char** argv); options (int argc, char** argv, int& end); bool help () const; const std::string& name () const; unsigned int level () const; ... }; int main (int argc, char* argv[]) { options o (argc, argv); if (o.help ()) print_usage (); if (o.level () > 4) cerr << "name is " << o.name () << endl; ... } It is easy to start using CLI in your application since there are no external dependencies. You can compile your command line interface to C++ and simply add the generated files to your project's source code. For a five minute introduction to CLI, see the "Hello World" example in the CLI Getting Started Guide: http://www.codesynthesis.com/projects/cli/doc/guide/#2 More information, documentation, and source code distributions are available from the project's web page: http://www.codesynthesis.com/projects/cli/ Enjoy, Boris