Written by

Question Joao Palma · Feb 18, 2019

%String to XML

Hi

I've got a string variable which I need to convert into a XML one.

My main goal here is to use the XML bit I've extracted from a HTML file in a message I need to pass over to an operation.

I'm doing the following which always errors

classMethod WriteNodes(myfile As %String)
{
    Set status=##class(%XML.TextReader).ParseString(myfile,.reader)

....

Any easy way of making this happen?

Kind regards

Comments

Robert Cemper · Feb 18, 2019

By XML bit I understand you have some myfile="<mynode>anytext</mynode>" or similar in hands

so this should cover your needs:

USER>set sc=##class(%XML.TextReader).ParseString(myfile,.reader)
USER>zwrite @reader.GlobalName
^||CacheTemp=1
^||CacheTemp(1,1)=$lb("element","","mynode","mynode",0,1)
^||CacheTemp(1,2)=$lb("chars","anytext","")
^||CacheTemp(1,3)=$lb("endelement","","mynode","mynode")

or is the content of myfile something else ?? 

0
Joao Palma  Feb 19, 2019 to Robert Cemper

That's correct Robert. Althougth, I always get the following error for the parse

comment or processing instruction expected while processing Anonymous Stream at line 1 offset 

0
Robert Cemper  Feb 22, 2019 to Joao Palma

Nice, you finally shared your real intentions.

0
Dinesh Ensemble  Sep 8, 2019 to Joao Palma

Hi Joao,

I have a similar requirement where I get an XML string as part of an email and I have managed to get the XML string from the input. But i'm lost on how to send it to either Business Process or Business Operation for further actions.

Appreciate if you can share information in this regard.

Thanks and Best Regards,

DCB

0
Eduard Lebedyuk  Feb 19, 2019 to Joao Palma

Please share the string you're trying to parse.

0
Joao Palma  Feb 19, 2019 to Eduard Lebedyuk

<Oceano>
    <Header>
        <DataSource>Oceano</DataSource>
        <DataType>EDAttendance</DataType>
    </Header>
    <Body>
        <MIU>
            <Department>BCH</Department>
            <TotalNumber>6</TotalNumber>
            <NumberWaitingToBeSeen/>
            <LongestWaitMin/>
        </MIU>
        <MIU>
            <Department>BOS</Department>
            <TotalNumber>1</TotalNumber>
            <NumberWaitingToBeSeen>1</NumberWaitingToBeSeen>
            <LongestWaitMin>109293</LongestWaitMin>
        </MIU>
    </Body>
</Oceano>

Hope this helps

0
Robert Cemper  Feb 19, 2019 to Joao Palma

structure is OK, and it worked for me.

Removing all CR,LF,TAB,BLANK still looks good here. 
Could you have some control  characters in your string ?

USER>ZZDUMP myfile may show it

USER>write $TR(myfile,$c(13,10,9,32))
<Oceano><Header><DataSource>Oceano</DataSource><DataType>EDAttendance</DataType></Header><Body><MIU><Department>BCH</Department><TotalNumber>6</TotalNumber><NumberWaitingToBeSeen/><LongestWaitMin/></MIU><MIU><Department>BOS</Department><TotalNumber>1</TotalNumber><NumberWaitingToBeSeen>1</NumberWaitingToBeSeen><LongestWaitMin>109293</LongestWaitMin></MIU></Body></Oceano>

0
Joao Palma  Feb 19, 2019 to Robert Cemper

This helped

write $TR(myfile,$c(13,10,9,32))

Thanks very much

0
Robert Cemper  Feb 19, 2019 to Joao Palma

BTW.

zwrite @reader.GlobalName

USER>zwrite @reader.GlobalName
^||CacheTemp=5
^||CacheTemp(5,1)=$lb("element","","Oceano","Oceano",0,1)
^||CacheTemp(5,2)=$lb("element","","Header","Header",0,2)
^||CacheTemp(5,3)=$lb("element","","DataSource","DataSource",0,3)
^||CacheTemp(5,4)=$lb("chars","Oceano","")
^||CacheTemp(5,5)=$lb("endelement","","DataSource","DataSource")
^||CacheTemp(5,6)=$lb("element","","DataType","DataType",0,3)
^||CacheTemp(5,7)=$lb("chars","EDAttendance","")
^||CacheTemp(5,8)=$lb("endelement","","DataType","DataType")
^||CacheTemp(5,9)=$lb("endelement","","Header","Header")
^||CacheTemp(5,10)=$lb("element","","Body","Body",0,2)
^||CacheTemp(5,11)=$lb("element","","MIU","MIU",0,3)
^||CacheTemp(5,12)=$lb("element","","Department","Department",0,4)
^||CacheTemp(5,13)=$lb("chars","BCH","")
^||CacheTemp(5,14)=$lb("endelement","","Department","Department")
^||CacheTemp(5,15)=$lb("element","","TotalNumber","TotalNumber",0,4)
^||CacheTemp(5,16)=$lb("chars","6","")
^||CacheTemp(5,17)=$lb("endelement","","TotalNumber","TotalNumber")
^||CacheTemp(5,18)=$lb("element","","NumberWaitingToBeSeen","NumberWaitingToBeSeen",0,4)
^||CacheTemp(5,19)=$lb("endelement","","NumberWaitingToBeSeen","NumberWaitingToBeSeen")
^||CacheTemp(5,20)=$lb("element","","LongestWaitMin","LongestWaitMin",0,4)
^||CacheTemp(5,21)=$lb("endelement","","LongestWaitMin","LongestWaitMin")
^||CacheTemp(5,22)=$lb("endelement","","MIU","MIU")
^||CacheTemp(5,23)=$lb("element","","MIU","MIU",0,3)
^||CacheTemp(5,24)=$lb("element","","Department","Department",0,4)
^||CacheTemp(5,25)=$lb("chars","BOS","")
^||CacheTemp(5,26)=$lb("endelement","","Department","Department")
^||CacheTemp(5,27)=$lb("element","","TotalNumber","TotalNumber",0,4)
^||CacheTemp(5,28)=$lb("chars","1","")
^||CacheTemp(5,29)=$lb("endelement","","TotalNumber","TotalNumber")
^||CacheTemp(5,30)=$lb("element","","NumberWaitingToBeSeen","NumberWaitingToBeSeen",0,4)
^||CacheTemp(5,31)=$lb("chars","1","")
^||CacheTemp(5,32)=$lb("endelement","","NumberWaitingToBeSeen","NumberWaitingToBeSeen")
^||CacheTemp(5,33)=$lb("element","","LongestWaitMin","LongestWaitMin",0,4)
^||CacheTemp(5,34)=$lb("chars","109293","")
^||CacheTemp(5,35)=$lb("endelement","","LongestWaitMin","LongestWaitMin")
^||CacheTemp(5,36)=$lb("endelement","","MIU","MIU")
^||CacheTemp(5,37)=$lb("endelement","","Body","Body")
^||CacheTemp(5,38)=$lb("endelement","","Oceano","Oceano")

0
Harshdeep Acharya  Mar 23, 2022 to Robert Cemper

Hello Robert,

I have faced issues when I can send the X12 204 EDI file as an input and I want an XML file as an output. So How can I achieve this in InterSystems IRIS 2021.1?
Also, I have shared my EDI file code as below:

ISA*01*0000000000*01*0000000000*ZZ*ABCDEFGHIJKLMNO*ZZ*123456789012345*101127*1719*U*00400*000003438*0*P*>
GS*SM*4405197800*999999999*20111219*1747*2100*X*004010
ST*204*0001
B2**XXXX**9999955559**PP
B2A*04
L11*NONPRIMARY*OK
MS3*XXXX*B**M
NTE**FROZEN GOODS SET TO -10d F
N1*PF*XYZ CORP*9*9995555500000
N3*31875 SOLON RD
N4*SOLON*OH*44139
N7**NONE*********FF****5300
S5*1*CL*27800*L*2444*CA*1016*E
L11*9999001947*DO
L11*9999670098*CR
L11*9999001866*DO
L11*9999669887*CR
G62*69*20111218
N1*SH*XYZ CORP*9*9991555550000
N2*TERMINAL FREEZER
N3*5555 TERMINAL RD
N4*CLEVELAND*OH*44023
S5*2*PU*3042*L*312*CA*146*E
L11*9999001866*DO
L11*9999595358*PO
L11*9999669887*CR
G62*70*20090728
N1*ST*1 EDI SOURCE*93*9990055555
N3*31875 SOLON RD
N4*SOLON*OH*44139
OID*9999669887*99999595358**PC*312*L*3042*E*146
L5**FREIGHT
G61*IC*FEEDBACK*EM*FEEDBACK@1edisource.com
S5*3*CU*24758*L*2132*CA*870*E
L11*9999001947*DO
L11*9999008881*PO
L11*9999670098*CR
G62*70*20111218
N1*ST*1 EDI SOURCE*93*9990055555
N3*55555 5TH AVE
N4*MAYFIELD*OH*44244
OID*9999670098*999608881**PC*2132*L*24758*E*870
L5**FREIGHT
G61*IC*FEEDBACK*EM*FEEDBACK@1edisource.com
L3*27800*G*******1016*E*2444*L
SE*46*0001
GE*1*2100
IEA*1*000002104

Thanks,

Harshdeep Acharya

0
Robert Cemper  Mar 23, 2022 to Harshdeep Acharya

sorry, I have no  idea what  X12 204 EDI is structured. or what you talk about

0
Harshdeep Acharya  Mar 23, 2022 to Robert Cemper

Ok. No issue.

Actually, I want to implement EDI X12 to XML conversion in InterSystems IRIS 2021. So can you help with this?

0
Joao Palma  Nov 21, 2019 to Dinesh Ensemble

Hi Dinesh

I'm not sure whether you still need help with this.

In summary what you need to do is to create a message of your own and then pass that string as a message property and do something like

 Set request.StringValue="test"
Set tSC = ..SendRequest( "Tutorial.ExampleOperation" ,request)
 

0
Sridhar Sanjeevi  Apr 5, 2023 to Eduard Lebedyuk

Hi Eduard I have a doubt on creating a XML message to send it through the HTTP . can you help me on this how to create a XML document .. I have tried with the below program but it showing the error <Method does not exist>
and am using Intersystem IRIS 2022.1.1 
set writer = ##class(%XML.Writer).%New()
set root = writer.StartDocument()
set person = root.Node("person")
person.Attribute("id") = "123"
person.Element("name").Characters("John Doe")
person.Element("age").Characters("30")
set xml = writer.EndDocument()
write xml

Can you help me on this issue

0
Joao Palma · Feb 22, 2019

To add up so we can help someone else...

This is what I really needed for this to work

Set reader = ##class(%XML.Reader).%New()
    Set status = reader.OpenString(messagedata)

    Do reader.Rewind()

    If $$$ISERR(status) {do $System.Status.DisplayError(status)}
    
    // Associate a class name with the XML element name
    Do reader.Correlate("MIU","Message.Request")
 

0