Unserialization of an arcobject in C++?

488
1
04-07-2010 01:21 AM
FrankPerks
New Contributor II
Hi, i basically have a IPolynomalXform operator, that has been serialized to XML. How can i unserialize this xml file into a ArcObject? Its very vaguley mentioned, in the EDN documentation, however i cannot find any examples.

My understanding is i need to use a combination of IXML* objects to read->unserialize->get_object->?????

HRESULT GeoTransformer::GetGeodataXFormFromFile(__in const ATL::CComBSTR& transformationFile)
{
 USES_CONVERSION;
 IXMLStreamPtr ipXMLStream(CLSID_XMLStream);
 IXMLSerializerPtr ipXMLSerializer(CLSID_XMLSerializer);
 
 ipXMLStream->LoadFromFile(transformationFile);
 
 
 IXMLReaderPtr ipXMLReader(CLSID_XMLReader);
 hr = ipXMLReader->ReadFrom(static_cast<IStreamPtr>(ipXMLStream));
 if(FAILED(hr))
 {
  std::cerr << "[ERROR]: Cannot read XML transformation file [ " << W2A(transformationFile) << " ]" << std::endl;
  return hr;
 }
 
 hr = ipXMLSerializer->ReadObject(ipXMLReader, ?????, ?????, ?????);
 if(FAILED(hr))
 {
  std::cerr << "[ERROR]: Cannot deserialize XML Transformation file [ " << W2A(transformationFile) << " ]" << std::endl;
  return hr;
 }
}


Any combination of parameters or attempts always results in an error. Does anyone know?
0 Kudos
1 Reply
FrankPerks
New Contributor II
Okay i figured it out. I'll share it just in case someone else ever needs to use it.


HRESULT GeoTransformer::GetGeodataXFormFromFile(__in const ATL::CComBSTR& transformationFile)
{
 USES_CONVERSION;
 IXMLStreamPtr ipXMLStream(CLSID_XMLStream);
 IXMLSerializerPtr ipXMLSerializer(CLSID_XMLSerializer);
 ipXMLStream->LoadFromFile(transformationFile);
 IXMLReaderPtr ipXMLReader(CLSID_XMLReader);
 hr = ipXMLReader->ReadFrom(static_cast<IStreamPtr>(ipXMLStream));
 if(FAILED(hr))
 {
  std::cerr << "[ERROR]: Cannot read XML transformation file [ " << W2A(transformationFile) << " ]" << std::endl;
  return hr;
 }
 
 LPUNKNOWN ipUnknown;
 
 hr = ipXMLSerializer->ReadObject(ipXMLReader, NULL, NULL, &ipUnknown);
 if(FAILED(hr))
 {
  std::cerr << "[ERROR]: Cannot deserialize XML Transformation file [ " << W2A(transformationFile) << " ]" << std::endl;
  return hr;
 }

 m_ipPolynomialFormX = static_cast<IPolynomialXformPtr>(ipUnknown);
 
 return S_OK;
}


But yeah no mention of how to do this anywhere on EDN. :mad:
0 Kudos