[xsd-users] hexBinary question.

Chip Bourne Clyde.Bourne at genband.com
Fri Nov 9 10:59:34 EST 2007


 
I have BCD byte values that I want to represent in a xsd:hexBinary
schema element, but I seem to be running into some sort of signing
problem.  When I construct an xml_schema::hex_binary with values greater
than 0x7f I abort.  What am I doing wrong?  Shouldn't hex_binary handle
this?

So,
            <?xml version="1.0" encoding="UTF-8"?>
            <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
                  <xs:element name="gtindicatorBCD"
type="xs:hexBinary"/>
            </xs:schema>

But when I try to marshal the following I abort after 0x7f

            #include "test.hxx"
            #include <string>
            #include <list>
            #include<iostream>
            #include<fstream>
            using namespace std;

            int main(int argc, void *argv[])
            {
                  for (unsigned char ii = 0; ii < 255; ii++)
                  {
                        xml_schema::namespace_infomap map;
                            map[""].name = "";
                            map[""].schema = "";

                        gtindicatorBCD(cout, xml_schema::hex_binary(&ii,
sizeof(ii)), map);
                  }
                  return 0;
            } 

I'm using xsd compiler version 
	XML Schema Definition Compiler 2.3.1

I can see that the encoding of a hexBinary does not handle values
greater than 127 properly; I just don't know if it should.
---from xsd/cxx/tree/types.txx	
      template <typename C, typename B>
      std::basic_string<C> hex_binary<C, B>::
      encode () const
      {
        std::basic_string<C> str;

        const char tab[] = "0123456789ABCDEF";

        if (size_t n = this->size ())
        {
          str.reserve (2 * n + 1);
          str.resize (2 * n);

          for (size_t i (0); i < n; ++i)
          {
            char byte (*(this->data () + i));
		/****** this shift drags sign ***********/
            unsigned char h (byte >> 4);
            unsigned char l (byte & 0x0F);

            str[2 * i] = C (tab[h]);
            str[2 * i + 1] = C (tab[l]);
          }
        }

Chip Bourne
Applications Business Unit

GENBAND Inc.
3701 W. Plano Pkwy., Suite 200
Plano, TX 75075 USA
office            +1.972.372.5026
mobile         +1.214.558.8897
facsimile     +1.972.238.1749
chip.bourne at genband.com
 
 <http://www.genband.com/> 
 





More information about the xsd-users mailing list