How to read and write values into Ens.StreamContainer
Hi Community,
I have SDA file as Ens.StreamContainer Message using pRequest As Ens.StreamContainer
SDA file structure looks like this
<Name><FamilyName>Lucy</FamilyName><GivenName>Hale</GivenName><MiddleName>Park</MiddleName></Name><Gender><Code>F</Code><Description>F</Description></Gender><BirthTime>2023-09-07T00:00:00</BirthTime>
How can i change individual value from the Steam and then save changed value into the stream?
Comments
Take a look at the following documentation:
https://docs.intersystems.com/irislatest/csp/docbook/DocBook.UI.Page.cl…
Hello smythe,
There are couple of ways to import your file into stream and convert to Ens.StreamContianer
First you can create a %FileCharacterStream object and link your file in to it. Create a streamcontainer object and send the created stream as a first parameter in %OnNew to Ens.StreamContiner class.
ClassMethod StreamContainer()
{
set file="dir\file"; Your directory and file name(C:\Intersystems\new13.txt)set file = ##class(%FileCharacterStream).%New()
do file.LinkToFile(file)
set strmContainer=##class(Ens.StreamContainer).%New(file)
zwrite strmContainer.Stream.Read($$$MaxLocalLength)
}Second, This way it's almost similar way. But Instead of pushing directly into Ens.Streamcontainer. You need to create a object for SDA. Import your file through XMLImportSDAString method to prepare SDA object. Now you have SDA object handy. So you can do any SDA stuffs with this object. Eventually it's an implicit step for validate your SDA file structure(Keep in mind the file structure should be exact XML format of SDA). Once the SDA object generated you can use Stream method generate stream from this SDA. Now you can convert to Ens.StreamContainer. Refer the below code to implement the above steps
ClassMethod FileToSDAToEnsContainer()
{
set file = ##class(%FileCharacterStream).%New()
do file.LinkToFile("C:\FHIRFILE\new13.txt")
set SDA3Container=##class(HS.SDA3.Container).%New()
do SDA3Container.XMLImportSDAString(file.Read($$$MaxLocalLength))
zwrite SDA3Container
do SDA3Container.ToQuickXMLStream(.stream)
set strmContainer=##class(Ens.StreamContainer).%New(stream)
zwrite strmContainer.Stream.Read()
}SDA may be too large to instantiate a Container object. Instead, use ##class(HS.SDA3.Container).InitializeXMLParse and ##class(HS.SDA3.Container).GetNextSDA to instantiate each streamlet.