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?Confused - Should xmltostruct instruction generate at least a feedback?Wink - Should assignment instruction generate at least a feedback?Wink Thanks in advance.

6 Comments

  1. 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" ConfusedConfusedConfusedCryCryCry


    Author: gianni (gianni.sandigliano@unifacesolutions.com)
  2. Hi, my first opinion: - The original xmlstream could be considered correct having two members same level with same ID?ConfusedYES - Should xmltostruct instruction generate at least a feedback?Wink NO, what was in the XML is now in the struct so no problem here - Should assignment instruction generate at least a feedback?Wink 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)
  3. Theo Neeskens said ... you would need to loop through the "children" of [level1].

    Is that possible? To loop through ordered positions instead of using names? I am not aware of it...Confused 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... Confused


    Author: gianni (gianni.sandigliano@unifacesolutions.com)
  4. gianni said
    Theo Neeskens said ... you would need to loop through the "children" of [level1].
    Is that possible? To loop through ordered positions instead of using names? I am not aware of it...Confused

    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)
  5. diseli said
    gianni said
    Theo Neeskens said ... you would need to loop through the "children" of [level1].
    Is that possible? To loop through ordered positions instead of using names? I am not aware of it...Confused
    Yes. ... Regards, Daniel

    Oh oh...that's an eye opening news...LaughLaughLaugh 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)
  6. gianni said Oh oh...that's an eye opening news...LaughLaughLaugh Thanks a lot Daniel! I wandered through last ULibrary for a while but without finding any reference to these syntaxes...wondering why... Thanks again!

     You are welcome! Smile But the stuff I've mentioned can also be found in the ULibrary. You start here: Wink

    • Programming in Uniface > Proc Language > Structs

    And then you work your way through the sub-topics. Smile The Struct access operators are described here:

    • Programming in Uniface > Proc Language > Structs > Struct Access Operators:
      • Struct Index Operator ({N})
      • Struct Collection Operator (->*)

    Also interesting: Cool

    • Programming in Uniface > Proc Language > Structs > Working with Structs
    • Programming in Uniface > Proc Language > Structs > Working With Structs: Code Examples

    And in case you are bored: WebEx: Structs In UnifaceWink Hope this helps. Kind regards, Daniel


    Author: diseli (daniel.iseli@uniface.com)