From omar.medina at web.de Thu Dec 8 19:16:51 2016 From: omar.medina at web.de (Omar Medina) Date: Fri Dec 9 10:10:07 2016 Subject: [studxml-users] Suggestion to extend the attribute template per compiler definiton Message-ID: <54b7b25d-db56-aaa0-49cb-9dce94115647@web.de> Hello dear Studxml-Users, my suggestion (below) involves a long known use-case, that impacts developers, when they are handling the read hexadecimal values from XML-data. They hex-string (0x...) needs to be previously processed before it will be converted. The same problems occurs with the provided attribute template of libstudxml, which can not handle directly hex-string The following code will thrown an exception, if the read string-value is described in the XML-file as a hex-string. Code XML p.next_expect(xml::parser::start_element,"drm"); p.content(xml::parser::content_type::complex); do { p.next_expect(xml::parser::start_element); p.content(xml::parser::content_type::complex); p.attribute("min"), p.attribute("max"), p.attribute("mean",0), p.attribute("factor",1), p.attribute("divisor",1), } p.next_expect(xml::parser::end_element); My suggestion: Either a compiler-definiton or an Api-Interface makes available the following code in the file "value-traits.txx" Current Suggestion - /* simple string trim function */ static bool is_not_whitespace(int c) { if ( (c == ' ') || /* whitespace */ (c == '\t') || /* tab */ (c == '\n') || /* linefeed */ (c == '\r') || /* carriage-return */ (c == '\f') || /* formfeed */ (c == '\v') /* vertical-tab */ ) return false; return true; } // trim from end static inline std::string &trimr(std::string &s) { s.erase(std::find_if(s.rbegin(), s.rend(), is_not_whitespace).base(), s.end()); return s; } // trim from begin static inline std::string &triml(std::string &s) { s.erase(s.begin(), std::find_if(s.begin(), s.end(), is_not_whitespace)); return s; } // trim from both ends static inline std::string &trim(std::string &s) { return trimr(triml(s)); } template T default_value_traits:: parse (std::string s, const parser& p) { T r; std::istringstream is (s); if (!(is >> r && is.eof ()) ) throw parsing (p, "invalid value '" + s + "'"); return r; } template T default_value_traits:: parse (std::string s, const parser& p) { bool h =false; T r; std::string ss = s; triml(ss); if((ss.length() > 2) && ((ss[0]=='0') && ((ss[1]=='x')||(ss[1]=='X')))) { ss[0]=' '; ss[1]=' '; h = true; } std::istringstream is (((h == true)? ss : s)); if (h == true) { if (!((is >> std::hex >> r) && is.eof ()) ) { throw parsing (p, "invalid value '" + s + "'"); } } else { if (!((is >> r) && is.eof ()) ) { throw parsing (p, "invalid value '" + s + "'"); } } return r; } By the way i want to take the opportunity to say thanks for the libstudxml. Best regards Omar -- -------------------------- Omar Martin Medina Izaguirre -------------------------- From boris at codesynthesis.com Mon Dec 12 11:16:08 2016 From: boris at codesynthesis.com (Boris Kolpackov) Date: Mon Dec 12 11:16:17 2016 Subject: [studxml-users] Suggestion to extend the attribute template per compiler definiton In-Reply-To: <54b7b25d-db56-aaa0-49cb-9dce94115647@web.de> References: <54b7b25d-db56-aaa0-49cb-9dce94115647@web.de> Message-ID: Hi Omar, Omar Medina writes: > my suggestion (below) involves a long known use-case, that impacts > developers, when they are handling the read hexadecimal values from > XML-data. I've been dealing with XML parsing for over 10 years now and it's the first time I encounter this "long known use-case" ;-). Besides, the problem with your approach is that not all strings that start with 0x are necessarily hex-encoded numbers. So we cannot embed such an assumption inside libstudxml. The good news is, the library allows you to provide a custom parsing specialization (via value_traits). So if in your application you can assume that anything that starts with 0x is a hex-number, then you can do it. Boris From omar.medina at web.de Tue Dec 13 18:25:26 2016 From: omar.medina at web.de (Omar Medina) Date: Wed Dec 14 11:55:00 2016 Subject: [studxml-users] Is possible to skip the current xml-element to the next In-Reply-To: References: <54b7b25d-db56-aaa0-49cb-9dce94115647@web.de> Message-ID: <05dcfdc4-7043-2e11-991b-b8f7db917156@web.de> Hello Mr. Boris Kolpackov, i am wondering if you could response my question about your library libstudxml. Do I have the possibility with the library libstudxml to skip the current element, also to the next element, for the case the the current element is not expected or it can not be processed. Suppose please in the small xml-example below : The application is only waiting for b-elements. The element is valid for the file but not for the application. Also, i want to skip the element to the next element. .... .... .... The intention is to continue with the reading of he XML-data and at the end of the reading all not used elements will be indicated. Thank in advance for your replay. best regard Omar -- -------------------------- Omar Medina -------------------------- From boris at codesynthesis.com Thu Dec 15 05:40:53 2016 From: boris at codesynthesis.com (Boris Kolpackov) Date: Thu Dec 15 05:41:02 2016 Subject: [studxml-users] Re: Is possible to skip the current xml-element to the next In-Reply-To: <05dcfdc4-7043-2e11-991b-b8f7db917156@web.de> References: <54b7b25d-db56-aaa0-49cb-9dce94115647@web.de> <05dcfdc4-7043-2e11-991b-b8f7db917156@web.de> Message-ID: Hi Omar, Omar Medina writes: > Do I have the possibility with the library libstudxml to skip the current > element, also to the next element, for the case the the current element is > not expected or it can not be processed. There is nothing automatic so you will have to handle skipping of unexpected elements in the application. Which should not be hard: just keep reading and ignoring elements while keeping track of the depth. Once you are back at depth 0, you resume processing. Or you could also do this with recursion. Boris