From paul.s.mcgrath at gmail.com Wed Oct 26 15:58:10 2022 From: paul.s.mcgrath at gmail.com (Paul McGrath) Date: Thu Oct 27 10:35:47 2022 Subject: [xsd-users] Saving Partial XSD trees In-Reply-To: References: Message-ID: I have been working through the cxx/tree/messaging example and altering it to my purpose. I have been able to input the file and output the file, however the output is missing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="matml31_lib.xsd" in the element when you compare it to the input file. Below is my adoption of the code as a Set and Get template functions. #pragma once #include // std::auto_ptr #include #include #include #include #include #include #include #include "dom-parse.hxx" #include "dom-serialize.hxx" #include "matml31_lib.hxx" using namespace bellshire; template bool MatML_Lib::Get(const std::string filename, MatML_Class*& element) { //// We need to initialize the Xerces-C++ runtime because we //// are doing the XML-to-DOM parsing ourselves. //// //::xercesc::XMLPlatformUtils::Initialize(); bool r(true); try { std::ifstream ifs; ifs.exceptions(std::ifstream::badbit | std::ifstream::failbit); ifs.open(filename); std::auto_ptr req; // Parse the XML request to a DOM document using the parse() // function from dom-parse.hxx. // { xml_schema::dom::auto_ptr<::xercesc::DOMDocument> doc(parse(ifs, filename, true)); ::xercesc::DOMElement& root(*doc->getDocumentElement()); req = xml_schema::element_map::parse(root); } // We can test which request we've got either using RTTI. // element = dynamic_cast (req.get()->_clone()); if (element) { r = true; } } catch (const xml_schema::no_element_info& e) { // This exception indicates that we tried to parse or serialize // an unknown element. // std::cerr << "unknown request: " << e.element_namespace() << "#" << e.element_name() << std::endl; r = false; } catch (const xml_schema::exception& e) { std::cerr << e << std::endl; r = false; } catch (const std::ios_base::failure&) { std::cerr << filename << ": unable to open or read failure" << std::endl; r = false; } //::xercesc::XMLPlatformUtils::Terminate(); return r; } template bool MatML_Lib::Set(const std::string filename, MatML_Class*& element) { // We need to initialize the Xerces-C++ runtime because we // are doing the XML-to-DOM parsing ourselves. // //::xercesc::XMLPlatformUtils::Initialize(); bool r(true); try { std::ofstream ofs; ofs.exceptions(std::ofstream::badbit | std::ofstream::failbit); ofs.open(filename); std::auto_ptr res(element->_clone()); // Serialize the response to a DOM document. // namespace xml = xsd::cxx::xml; const XMLCh ls_id[] = { xercesc::chLatin_L, xercesc::chLatin_S, xercesc::chNull }; ::xercesc::DOMImplementation* impl( ::xercesc::DOMImplementationRegistry::getDOMImplementation(ls_id)); const std::string& name(res->_name()); const std::string& ns(res->_namespace()); xml_schema::dom::auto_ptr<::xercesc::DOMDocument> doc( impl->createDocument( xml::string(ns).c_str(), xml::string("" + name).c_str(), 0)); xml_schema::element_map::serialize(*doc->getDocumentElement(), *res); // Serialize the DOM document to XML using the serialize() function // from dom-serialize.hxx. // //std::cout << "response:" << std::endl // << std::endl; serialize(/*std::cout*/ofs, *doc); } catch (const xml_schema::no_element_info& e) { // This exception indicates that we tried to parse or serialize // an unknown element. // std::cerr << "unknown request: " << e.element_namespace() << "#" << e.element_name() << std::endl; r = false; } catch (const xml_schema::exception& e) { std::cerr << e << std::endl; r = false; } catch (const std::ios_base::failure&) { std::cerr << filename << ": unable to open or read failure" << std::endl; r = false; } //::xercesc::XMLPlatformUtils::Terminate(); return r; } On Sun, Sep 11, 2022 at 7:39 AM Boris Kolpackov wrote: > Paul McGrath writes: > > > I'm looking to save sequences without requiring having to save the whole > > tree. The rationale behind this is to create a library of elements that > can > > be then cloned into a tree. > > Each XML Schema type is mapped to a C++ class that comes with a > parsing constructor (from DOMElement) and a serialization operator<< > (to DOMElement). So with some effort (i.e., create suitable DOMElement, > etc) you should be able to serialize a sequence of instances of such > classes. > > The closest example to what you are trying to achieve is probably > cxx/tree/messaging/ (it also comes with DOM parsing/serialization > helpers which you will most likely find useful). There is also > cxx/tree/streaming/ that you may find relevant. > From muralidhara.bk at microfocus.com Thu Oct 27 05:51:35 2022 From: muralidhara.bk at microfocus.com (Muralidhara B K) Date: Thu Oct 27 10:36:31 2022 Subject: [xsd-users] Regarding bugs - Type Mismatch: Signed to Unsigned Message-ID: Hi Team, As part of static code analysis , bugs are reported against codes in codeSynthesis/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/char-utf8.txx. Issue Type : Type Mismatch: Signed to Unsigned Issue are as listed below, 1. The function in char-utf8.txx is declared to return an unsigned value, but on line 155 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. 2. The function in char-utf8.txx is declared to return an unsigned value, but on line 204 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. 3. The function in char-utf8.txx is declared to return an unsigned value, but on line 220 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. 4. The function in char-utf8.txx is declared to return an unsigned value, but on line 235 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. 5. The function in char-utf8.txx is declared to return an unsigned value, but on line 243 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. 6. The function in char-utf8.txx is declared to return an unsigned value, but on line 258 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. 7. The function in char-utf8.txx is declared to return an unsigned value, but on line 266 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. 8. The function in char-utf8.txx is declared to return an unsigned value, but on line 274 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. Kindly please let us know is there any fix is available for this issue or is there any plan to fix this in upcoming release. If so please let us know when will be the fix available and in which release . Thanks & Regards, Murali SW Engr (Applications) - AutoPass +91 9611208625 muralidhara.bk@microfocus.com [cid:image001.png@01D8EA13.1A801730] -------------- next part -------------- A non-text attachment was scrubbed... Name: image001.png Type: image/png Size: 2565 bytes Desc: image001.png Url : https://codesynthesis.com/pipermail/xsd-users/attachments/20221027/3ec738ea/image001.png From boris at codesynthesis.com Fri Oct 28 04:34:10 2022 From: boris at codesynthesis.com (Boris Kolpackov) Date: Fri Oct 28 04:28:16 2022 Subject: [xsd-users] Saving Partial XSD trees In-Reply-To: References: Message-ID: Paul McGrath writes: > I have been able to input the file and output the file, however the output > is missing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > xsi:noNamespaceSchemaLocation="matml31_lib.xsd" in the element when you > compare it to the input file. With custom serialization via DOM, you need to add these attributes yourself. From paul.s.mcgrath at gmail.com Fri Oct 28 08:45:13 2022 From: paul.s.mcgrath at gmail.com (Paul McGrath) Date: Fri Oct 28 08:50:11 2022 Subject: [xsd-users] Saving Partial XSD trees In-Reply-To: References: Message-ID: Thanks for the pointer. I was able to use the FAQ and add the following code to the Set function. This allows the output file to be also the input file which is exactly that I wanted. Thanks again for your help. Paul xml_schema::dom::auto_ptr<::xercesc::DOMDocument> doc( impl->createDocument( xml::string(ns).c_str(), xml::string("" + name).c_str(), 0)); ::xercesc::DOMElement * root(doc->getDocumentElement()); root->setAttributeNS( xml::string("http://www.w3.org/2000/xmlns/").c_str(), xml::string("xmlns:xsi").c_str(), xml::string("http://www.w3.org/2001/XMLSchema-instance ").c_str()); root->setAttributeNS( xml::string("http://www.w3.org/2000/xmlns/").c_str(), xml::string("xmlns:xsd").c_str(), xml::string("http://www.w3.org/2001/XMLSchema").c_str()); root->setAttributeNS( xml::string("http://www.w3.org/2001/XMLSchema-instance ").c_str(), xml::string("xsi:noNamespaceSchemaLocation").c_str(), xml::string("matml31_lib.xsd").c_str()); xml_schema::element_map::serialize(*doc->getDocumentElement(), *res); // Serialize the DOM document to XML using the serialize() function // from dom-serialize.hxx. // //std::cout << "response:" << std::endl // << std::endl; serialize(/*std::cout*/ofs, *doc); On Fri, Oct 28, 2022 at 4:34 AM Boris Kolpackov wrote: > Paul McGrath writes: > > > I have been able to input the file and output the file, however the > output > > is missing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:noNamespaceSchemaLocation="matml31_lib.xsd" in the element when you > > compare it to the input file. > > With custom serialization via DOM, you need to add these attributes > yourself. > From boris at codesynthesis.com Mon Oct 31 08:21:45 2022 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Oct 31 08:15:48 2022 Subject: [xsd-users] Regarding bugs - Type Mismatch: Signed to Unsigned In-Reply-To: References: Message-ID: Muralidhara B K writes: > As part of static code analysis , bugs are reported against codes > in codeSynthesis/xsd-4.0.0-i686-windows/libxsd/xsd/cxx/xml/char-utf8.txx. > > Issue Type : Type Mismatch: Signed to Unsigned > > Issue are as listed below, > > 1. The function in char-utf8.txx is declared to return an unsigned value, but on line 155 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. > 2. The function in char-utf8.txx is declared to return an unsigned value, but on line 204 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. > 3. The function in char-utf8.txx is declared to return an unsigned value, but on line 220 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. > 4. The function in char-utf8.txx is declared to return an unsigned value, but on line 235 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. > 5. The function in char-utf8.txx is declared to return an unsigned value, but on line 243 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. > 6. The function in char-utf8.txx is declared to return an unsigned value, but on line 258 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. > 7. The function in char-utf8.txx is declared to return an unsigned value, but on line 266 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. > 8. The function in char-utf8.txx is declared to return an unsigned value, but on line 274 it returns a signed value. The function is declared to return an unsigned number but returns a signed value. Firstly, there is no function return on these lines. Rather, it's an assignment of char to unsigned char as part of the UTF8 sequence analysis. These are not bugs but we can add explicit casts if that helps.