Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:05:02+00:00 2026-06-04T02:05:02+00:00

Using Xerces C++ I generated the typical C++ code from the below schema. Upon

  • 0

Using Xerces C++ I generated the typical C++ code from the below schema. Upon serialization of an object I get an access violation. I stepped through the code way down the stack until some templated insertion code for a std::basic_string and it seems to be happening there.

I could go into where in the generated code the problem happens. But it seems to be overkill. I’m sure this is an issue with my code.

My Code is below.

#include <sstream>
#include <iostream>
#include "..\XMLObjects\SomeXML.hxx"

void serializeObject(Object* mess, std::string& result);
void create();

int _tmain(int argc, _TCHAR* argv[])
{
create();
return 0;
}

void create()
{
std::string result;

objectType oType("Status");
std::auto_ptr<Object> obj( &Object(oType) );

time_t seconds=time(NULL);

Object::status_type s(seconds);
obj->status().set(s);
obj->status()->timeOfUpdate();
serializeObject(obj.get(), result);

}

void serializeObject(Object* mess, std::string& result)
{

std::ostringstream buff;
xml_schema::namespace_infomap nsm;
nsm[""].name = "";
nsm[""].schema = "SomeXML.xsd";

try
{
    Object_(buff, *mess, nsm, "UTF-8", xml_schema::flags::no_xml_declaration);
}
catch (const xml_schema::exception& e)
{
    std::cout << e << std::endl;
    return;
}
catch(std::exception& ex)
{
    std::string info(" Caught the exception ");
    info+=ex.what();

}
catch(...)
{
    std::string info(" Caught an exception ");

}

    result=buff.str().c_str();

}

The following is the schema I’m using to generate the code.

    <?xml version="1.0" encoding="utf-8"?>

  <!--<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.example.com/SomeXML">-->

  <xsd:complexType name ="Status" >
    <xsd:sequence>
      <xsd:element name="timeOfUpdate" type="xsd:unsignedLong" minOccurs="1" maxOccurs="1"/>
    </xsd:sequence>
  </xsd:complexType>


  <xsd:simpleType name="objectType">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Status"/>
      <xsd:enumeration value="Thing A"/>
      <xsd:enumeration value="Thing B"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="Object" >
   <xsd:sequence>
     <xsd:element name="objectType" type ="objectType" minOccurs="1" maxOccurs="1" />
      <xsd:element name ="status" type ="Status" minOccurs="0" maxOccurs="1"/>
    </xsd:sequence>

  </xsd:complexType >


  <xsd:element name="Object" type="Object" />
</xsd:schema>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T02:05:03+00:00Added an answer on June 4, 2026 at 2:05 am

    std::auto_ptr<Object> obj( &Object(oType) );

    This is most likely one source of headache. This looks like you’re creating a temporary, and then taking it’s address, and storing it in an auto_ptr.

    The temporary then immediately goes out of scope, and you’re left with a dangling pointer. Also, when it reaches the end of the scope, it’ll try to delete a pointer that was originally on the stack.

    Try replacing it with

    std::auto_ptr<Object> obj( new Object(oType) );

    or, if you’re using a C++11 compatible compiler, use

    std::unique_ptr<Object> obj( new Object(oType) );

    since auto_ptr has been deprecated in the latest standard.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to convert an Xml String to XML DOM object using Xerces
I am using SAX2 from Xerces-C to read an XML document. However, I would
I'm going to get a book that uses Xerces C++. I'm currently using VS
I have a Java application that parses a large xml schema (.xsd) using Xerces
I am using Xerces 2.9.1 to perform some XML parsing. The XML contains namespace
Using LINQ on collections, what is the difference between the following lines of code?
i am using Xerces to do some xml writing. here's a couple of lines
i have the following function i wrote to create an XML file using Xerces
I'm using the Xerces C++ DOM parser to read some XML files in a
I am using Xerces in Java. I would like to parse an HTML document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.