I have a bigtext variable that holds an xml document. I would like to load this into an XML Document using XML DOM automation.
I tried XMLDOC.loadxml(bigtext) but the XMLDOM is expecting a text variable (Bigtext is not consider text).
So I thought I could load the bigtext variable into an instream. This way I could load the XML Doc with:
XMLDOC.load(Instream);
How can I create an instream object from my Bigtext variable?
0
Comments
I am afraid you could not create the instream variable from BigText.
However, you can create a record variable and use TempBlob as SubType
TempBlob is virtual table in Navision and very helpful to handle long text or binary data.
Roughly, the codes should be like following:
Note: You can set Temporary property as YES for TempBlob variable
Var readStream as InStream
Var writeStream as OutStream
TempBlob.Init;
TempBlob.Blob.CREATEOUTSTREAM(writeStream);
BigText.Write(writeStream); //-->store the big text xml to blob field
TempBlob.Blob.CalcFields(Blob); //--> to refresh up the blob field
TempBlob.Blob.CREATEINSTREAM(readStream);
XMLDOM.LOAD(readStream); //--> load your big xml text here
In short, use tempblob virtual table as mediator.
Good luck..
Cheers,
mandyk
jwilder@stonewallkitchen.com
Here's my code (PassXMLString is a Bigtext variable):
TempBlob.Blob.CREATEOUTSTREAM(StreamOut);
PassXMLString.WRITE(StreamOut);
TempBlob.CALCFIELDS(Blob);
TempBlob.Blob.CREATEINSTREAM(StreamIn);
CREATE(XMLDoc);
XMLDoc.load(StreamIn);
XMLNodeCurr := XMLDoc.documentElement;
XMLNodeCurr := XMLNodeCurr.selectSingleNode('OrderHeader/CustomerNo');
EXIT(XMLNodeCurr.text);
This would be working except that somehow in this process a character was added to the InStream/Blob at the very end. This character makes the XML not valid anymore. If I export the blob and remove the last character the file is valid again.
Any thoughts?
jwilder@stonewallkitchen.com
XMLDOC.loadxml(format(bigtext));