HowTo deal with more struct members at same level with same id?
Author: gianni.sandigliano@unifacesolutions.com (gianni)
Hi all, after an xmltostruct (after it $status = 0 and $procerror = 0) i am getting myStruct with two members at same level with same id (and obviously different values)...something like: [myStruct] [level1] = "value1" [level21] = "value21" [level22] = "value22First" [level22] = "value22Second" I need to save those two values to use them later on in my application...but if I try to address them copying values to myField with this instruction: myField = myStruct->level1->level22 I am getting nothing ...myField is originally null and remained null... ($status = 0 and $procerror = 0). I can obviously search text withing original xmlstream to extract what I need but I was wondering if there is a more elegant way to solve this issue... Any idea? Some other toughts: - The original xmlstream could be considered correct having two members same level with same ID? - Should xmltostruct instruction generate at least a feedback?
- Should assignment instruction generate at least a feedback?
Thanks in advance.
6 Comments
Local Administrator
In a more detailed analysis of the original xmlstream I've recognized case described is not single! Also on level3 there is a similar repeation; something like: [myStruct] [level1] = "value1" [level21] = "value21" [level22] = "value22First" [level22] = "value22Second" [level23] = "value23" [permission] = "value231" [permission] = "value232" [mapping] = "value238" [mapping] = "value239"




Author: gianni (gianni.sandigliano@unifacesolutions.com)
Local Administrator
Hi, my first opinion: - The original xmlstream could be considered correct having two members same level with same ID?
YES - Should xmltostruct instruction generate at least a feedback?
NO, what was in the XML is now in the struct so no problem here - Should assignment instruction generate at least a feedback?
YES, it would be nice if there was a $status/$procerror for "requested value is not unique" Obviously your statement myField = myStruct->level1->level22 cannot give a result on this struct as it does not ask for a unique value. In order to get values from the non-unique members you would need to loop through the "children" of [level1].
Author: Theo Neeskens (tneeskens@itblockz.nl)
Local Administrator
Is that possible? To loop through ordered positions instead of using names? I am not aware of it...
I've tried already to rename culprit nodes with: myStruct->level1->level22->$name = "level22a" but also $name is applied to all cases without any possibility to filter...
Author: gianni (gianni.sandigliano@unifacesolutions.com)
Local Administrator
Yes. For example: myField = myStruct->level1->level22{1} ; myField = "value22First" myField = myStruct->level1->level22{2} ; myField = "value22Second" Or you do this: $1 = myStruct->level1->*{1} ; $1 = "value21" $2 = myStruct->level1->*{1}->$name ; $2 = "level21" $1 = myStruct->level1->*{2} ; $1 = "value22First" $2 = myStruct->level1->*{2}->$name ; $2 = "level22" $1 = myStruct->level1->*{3} ; $1 = "value22Second" $2 = myStruct->level1->*{3}->$name ; $2 = "level22" You could of course use a for loop to go through all the Struct nodes. And if you would like to assign a value from a Struct to a field then you can check with the Struct function $isScalar if a Struct node is a scalar Struct (has a value). if (myStruct->level1->level22->$isScalar) myField = myStruct->level1->level22 else message/info "myStruct->level1->level22 is not a scalar Struct node" endif Hope this helps. Regards, Daniel
Author: diseli (daniel.iseli@uniface.com)
Local Administrator
Oh oh...that's an eye opening news...

Thanks a lot Daniel! I wandered through last ULibrary for a while but without finding any reference to these syntaxes...wondering why... Thanks again!
Author: gianni (gianni.sandigliano@unifacesolutions.com)
Local Administrator
You are welcome!
But the stuff I've mentioned can also be found in the ULibrary. You start here:
And then you work your way through the sub-topics.
The Struct access operators are described here:
Also interesting:
And in case you are bored: WebEx: Structs In Uniface
Hope this helps. Kind regards, Daniel
Author: diseli (daniel.iseli@uniface.com)