Domanda

Is there a simple way for me to take an IStream of an XML document and then load it in to an IXMLDOMDocument (msxml)? Preferably without writing the stream to disk.

È stato utile?

Soluzione

Check this out! More example.

An std::istream based ISequentialStream implementation example: link. (ISequentialStream is the base class of IStream).

// VARIANT_TRUE != TRUE !!!!!!!!!!!
VARIANT_BOOL retval = VARIANT_TRUE;
// document object created by CoCreateInstance
IXMLDOMDocument* xml_doc;
// own ISequentialStream/IStream instance (like example)
ISequentialStream* streamaddress;
// variant: could be IStream, ISequentialStream or IPersistStream
VARIANT xmlSource;
// variant init
VariantInit(&xmlSource);
// your object is an IUnknown interface
xmlSource.vt = VT_UNKNOWN;
// set its address
xmlSource.punkVal = streamaddress;
// load XML from stream
if ( ( xml_doc->load(xmlSource,&retval) == S_OK ) && ( retval == VARIANT_TRUE ) ) {
  // done
}

VARIANT_TRUE

Altri suggerimenti

You probably want to use SHCreateMemStream:

bool load_xml_string(IXMLDOMDocument* xml_doc, std::string const& xml_string){
  CComPtr<IStream> stream;
  stream.Attach(SHCreateMemStream((const BYTE*)xml_string.c_str(),
                                  (UINT)xml_string.size()));
  VARIANT_BOOL load_result = VARIANT_FALSE;
  return (xml_doc->load(CComVariant(static_cast<IUnknown*>(&stream)), &load_result) == S_OK &&
          load_result == VARIANT_TRUE);
}

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top