[xsd-users] Re: Help me: Access Violation on optional element during serialization

James Mei jxmei3 at gmail.com
Wed Oct 28 04:49:26 EDT 2009


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<char>::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 <jxmei3 at gmail.com> 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 <typename C>
>         XMLCh* char_transcoder<C>::
>         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
>



More information about the xsd-users mailing list