Dear,
we are trying to simulate an example from de Rocket Library, but this does not work:
XML Attribute
Our code
variables
struct vStruct
string vXML
endvariables
vStruct = $newstruct
vStruct -> para= "txt"
vStruct -> para -> $tags -> xmlClass = "element"
vStruct -> para -> audience = "admin"
vStruct -> para -> audience -> $tags -> xmlClass = "attribute"
putmess vStruct -> $dbgstring
; $dbgstring returns following result
[]
[para]
[$tags]
[xmlClass] = "element"
"txt"
[audience] = "admin"
[$tags]
[xmlClass] = "attribute"
structtoxml vXml,vStruct
; the xml however gives us :
<para>txt</para>
; where we would expect <para audience="admin">txt</para>
; any ideas (someone)
; we hope that any solution that will be given will also work for structToJson
------------------------------
Geert Dupont
Zorgi NV
Mechelen BE
------------------------------
Hi Geert,
You're almost there. I often do a conversion from the desired result first to work out what the target struct looks like by examining $dbgString, e.g.
vXML = "<para audience=%%"admin%%">text</para>"
xmltostruct vStruct, vXML
The trick to replicating the structure in this case is that "txt" is an attribute that has no $name. There might be a better way of doing it, but I just used the struct collection reference to add a second attribute like this: vStruct->para->*{2} = "text" (You could add a $newstruct beforehand, but I don't think it is necessary in this case).
So my test code looks like this:
vStruct->para = $newstruct
vStruct->para->$tags->xmlClass = "element"
vStruct->para->audience = "admin"
vStruct->para->audience->$tags->xmlClass = "attribute"
vStruct->para->*{2} = "text"
putmess vStruct -> $dbgstring
structtoXML vXML, vStruct
I hope that helps. A similar technique should work with JSON, but you'll need to set different $tags.
Kind Regards,
------------------------------
David Akerman
Principal Solution & Enablement Architect
Rocket Internal - All Brands
------------------------------
Hi Geert,
You're almost there. I often do a conversion from the desired result first to work out what the target struct looks like by examining $dbgString, e.g.
vXML = "<para audience=%%"admin%%">text</para>"
xmltostruct vStruct, vXML
The trick to replicating the structure in this case is that "txt" is an attribute that has no $name. There might be a better way of doing it, but I just used the struct collection reference to add a second attribute like this: vStruct->para->*{2} = "text" (You could add a $newstruct beforehand, but I don't think it is necessary in this case).
So my test code looks like this:
vStruct->para = $newstruct
vStruct->para->$tags->xmlClass = "element"
vStruct->para->audience = "admin"
vStruct->para->audience->$tags->xmlClass = "attribute"
vStruct->para->*{2} = "text"
putmess vStruct -> $dbgstring
structtoXML vXML, vStruct
I hope that helps. A similar technique should work with JSON, but you'll need to set different $tags.
Kind Regards,
------------------------------
David Akerman
Principal Solution & Enablement Architect
Rocket Internal - All Brands
------------------------------
David,
thanks for the speedy & helpfull response. This seems to work.
The StructoJson however gives me following message (via $procReturnContext)
Context=StructToJSONWarnings=1DETAILS=SEVERITY=WarningCURRENTSTRUCT=""->para{1}ADDITIONAL=Encountered array struct member with a name: audience
{"para":["admin","text"]}
I suppose we can ignore this?
the result seems correct (to me)
{"para":["admin","text"]}
if i change the code in following way
(i removed the tags since not needed for JSon conversion)
vStruct->para = $newstruct
vStruct->para->*{1} = "admin"
vStruct->para->*{2} = "text"
$procReturnContext does not return warnings
Kind regards,
Geert
------------------------------
Geert Dupont
Zorgi NV
Mechelen BE
------------------------------