How can I save a xmldoc to stream?

SunsetSunset Member Posts: 201
I have a codeunit where I am recieving TempBlob containing an xml. I am handling and processing the xml, and end up with a new xml that I want to return. But for some reason the stream is empty when returning ](*,)

Snippets from the code
//Create XML
CLEAR(TempBlob);
TempBlob.Blob.CREATEOUTSTREAM(Outstr);
XMLport.SETDESTINATION(Outstr);
XMLport.EXPORT;

Works fine, my Outstr has the resulting xml document
// Process Document
ProcessDocument(TempBlob);


//What are we recieving
CREATE(lXmlDoc);

TempBlob.Blob.CREATEINSTREAM(Instr);

lXmlDoc.async := FALSE;
lXmlDoc.load(Instr);

lXmlDoc.save('C:\temp\xmlport.xml');

ProcessDocument takes the TempBlob record as a Var

The function extracts the document from TempBlob processes it and ends up with a xmldoc ('Microsoft XML, v6.0'.DOMDocument)

But when trying to put the XMLDoc back into the TembBlob stream it goes blank for some reason
XmlDoc.load(XmlHttp.responseXML);
ProcessDoc.Blob.CREATEOUTSTREAM(Outstr);

//XmlDoc.save('C:\temp\xmlport.xml');

XmlDoc.save(Outstr);

If I use the XMLDoc.Save the file is there, but when I'm back to where I called the function, the stream is empty, or at least I can't load anything from it :cry:

Does anybody have some suggestions as to what I am missing?

N.B. Yes I know that I can just save the xml and then load it when I return from the function, but the whole idea is to work within the streams and not having to have disc access.
Don't just take my word for it, test it yourself

Comments

  • robwillrobwill Member Posts: 5
    Hi there,

    One of the things perhaps I would check is the state of Temp.Blob variable prior to assign it XML doc.

    e.g.

    if tempblob.Blob.HASVALUE then begin
    //Now Create Instream
    tempblob.Blob.CREATEINSTREAM(InsStr);

    //Assign it to XML doc
    lXmlDoc.async := FALSE;
    lXmlDoc.load(Instr);

    end else begin
    //Create a quick XML message that contain Node for return
    end;

    If Temp.Blob is Null I would then investigate ProcessDocument function.

    Hope this help.
  • GRIZZLYGRIZZLY Member Posts: 127
    I'm wondering with what parameters you've call XmlHttp object?
    The main parameter is to send request with POST option (it means that system should wait for response, in other words, system will work in synchronous way), the second option is to say to XmlHttp object, that request should be in xml\html.

    You could try to go on with my example:
    IF ISCLEAR(XmlHttp) THEN CREATE(XmlHttp);
    XmlHttp.setTimeouts(TimeOutms, TimeOutms, TimeOutms, TimeOutms);
    XmlHttp.open('POST',GenSetupL."SMS Service Url",FALSE);
    XmlHttp.setRequestHeader('Content-Type','text/xml');
    XmlHttp.send(RequestText);
    
    IF NOT XMLResponse.loadXML(XmlHttp.responseText) THEN ERROR(WrongResponse);
    IF ISCLEAR(XMLResponse) THEN ERROR(WrongResponse);
    
    Sincerely yours, GRIZZLY
    Follow my blog at http://x-dynamics.blogspot.com
  • MarkoMarko Member Posts: 4
    Have you tried to call TempBlob.CALCFIELDS(Blob) before creating the instream?
    Marco Vicentini
    Loving/Hating Navision since 2006
Sign In or Register to comment.