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 7959693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:36:49+00:00 2026-06-04T04:36:49+00:00

I’m having an issue where I serialize an object to a string and then

  • 0

I’m having an issue where I serialize an object to a string and then create it again from the same string. When I try and create the same object from the string and check the values, the functions aren’t returning correctly. It returns the whole XML object as a string.

I looked at the resulting xml and it looks correct. So I’m at a loss as to what to do.

Thanks for any insight into this issue.

An example is below.

#include "XMLHelper.hxx"

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

int _tmain(int argc, _TCHAR* argv[])
{

   XmlHelper::objectType oType(XmlHelper::objectType::Status);
   XmlHelper::Object obj(oType);

   unsigned long time(134000000);
   XmlHelper::Status status(time);
   obj.status().set(status);

   std::string result;

   serializeObject(obj, result);


   if (obj.status().present()  )
   {
    std::cout<<"Message is Status"<<std::endl;
   }
   if (obj.objectType() == "Status" )
   {
    std::cout<<"Message is Status"<<std::endl;
   }
   if (obj.objectType() == XmlHelper::objectType::Status )
   {
    std::cout<<"Message is Status"<<std::endl;
   }

   XmlHelper::Object otherObj(result);

   if (otherObj.status().present()  )
   {
    std::cout<<"Message is Status"<<std::endl;
   }
   else if (otherObj.objectType() == "ThingA")
   {
    std::cout<<"Message is ThingA"<<std::endl;
   }
   else if (otherObj.objectType() == "ThingB")
   {
    std::cout<<"Message is ThingB"<<std::endl;
   }

   return 0;
}

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

    std::ostringstream buff;
    xml_schema::namespace_infomap nsm;

    nsm[""].schema = "XMLHelper.xsd";

    Object_(buff, mess, nsm, "UTF-8", xml_schema::flags::no_xml_declaration);

    result=buff.str();

 }

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">

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


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

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

  <xsd:complexType name ="ThingB" >
    <xsd:sequence>
      <xsd:element name="number" 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="ThingA"/>
      <xsd:enumeration value="ThingB"/>
    </xsd:restriction>
  </xsd:simpleType>

  <xsd:complexType name="Object" >
    <xsd:sequence>
      <xsd:element name="objectType" type ="objectType" minOccurs="1" maxOccurs="1" />
      <xsd:element name ="thingA" type ="ThingA" minOccurs="0" maxOccurs="1"/>
      <xsd:element name ="thingB" type ="ThingB" minOccurs="0" 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-04T04:36:50+00:00Added an answer on June 4, 2026 at 4:36 am

    Come to find out I was doing the building of the object which parses the XML completely wrong. What seems to be the correct way is the below.

    std::istringstream iss (result); 
    std::auto_ptr<XmlHelper::Object> otherObj(XmlHelper::Object_(iss)); 
    

    I also didn’t have my xsd file in the correct directory.

    Hopefully, this helps someone else.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.