Avoiding empty tags in structtoxml | Uniface 9 | Forum

Avatar

Please consider registering
guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

—  Results per page  —








— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters
For a group of consecutive words like 'end of support' use Match phrase

sp_Feed Topic RSS sp_TopicIcon
Avoiding empty tags in structtoxml
06 Nov 2018
5:14 pm
Avatar
Theo Neeskens
Member
Forum Posts: 371
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

Hi,

I have a situation where I need to:

– retrieve lots of related data in a Uniface service

– create a struct using componenttostruct

– create XML using structtoxml

– dump the XML as a file on disk 

 

It works fine so far, but I do not want empty XML tags in the output.

– Is there a way to specify a switch on componenttostruct so I do not get the empty fields in the struct?

– Is there a way to specify a switch on structtoxml so I do not get the empty fields in the XML?

 

NB: It needs to be fast, and the code needs to be kept extremely simple, so the answer “just iterate over the struct and remove them yourself” is not the answer that I am hoping for…

Theo Neeskens, Uniface Consultant and general problem solver at ITBLOCKZ
07 Nov 2018
8:20 am
Avatar
ulrich-merkel
Frankfurt/Germany
Member
Forum Posts: 1890
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

Hi Theo,

if such a switch can not be found in the current uniface version:

what about creating a .RAW output file at first
and then use a tiny AWK script which doesn’t copy lines with empty tags
to the real output file (and you delete the RAW file afterwards).

I use GAWK.EXE and for simple tasks like this, it works pretty fast.

BTW: this could process your “renaming elements requirement” as well

07 Nov 2018
11:42 am
Avatar
gianni
Member
Forum Posts: 357
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

Hi Theo,

my gotfeel is same as Uli:  the switch you are looking for is not available as of current U9.7 & U10.3 but
I’ve read about a new switch structtoxml/schema that is promising a lot but I have not had yet time to dig it.

My suggestion is simple: if you do not own an horse but just a donkey/ass, jump on your donkey/ass and go where you have to go!
Is it less confortable, less elegant and less fast? yes! Could it bring you to your destination? yes!
Let’s iterate over the struct before converting to XML and apply there your business rules whatever they are!
If you want to be future proof built your own functions to be reused next time you will find same requirement.

My 2 cents…

Gianni

07 Nov 2018
12:03 pm
Avatar
TK
New Member
Forum Posts: 1
Member Since:
13 Mar 2018
sp_UserOfflineSmall Offline

Hi,

a time ago i had a similar problem. This was my solution, for empty nodes in a struct.

Maybe this could help to find your solution.

entry en_cleanup
params
numeric lp_rc : OUT
byref struct lp_struct : INOUT
endparams
variables
numeric lv_rc
numeric lv_counter
endvariables

for lv_counter = lp_struct->$membercount to 1 step -1
lv_rc = 0
if (!lp_struct->*{lv_counter}->$isScalar) call en_cleanup(lv_rc, lp_struct->*{lv_counter}) ; === handle sub-nodes
if (lv_rc < 0) lp_struct->*{lv_counter}->$parent = “” ; === Remove node from struct
endfor

if (lp_struct->$membercount == 0) lp_rc = -1 ; === node is empty

return(0)
end

07 Nov 2018
2:17 pm
Avatar
Theo Neeskens
Member
Forum Posts: 371
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

Thanks all,

If I can`t do this with a simple switch or setting, I will probably do this with xslt, as we need to perform many more transformations.

I just tought it would be evident to have this in componenttostruct, as it will often deliver a much smaller struct that is faster to process.

Regards,

Theo Neeskens
Consultant at ITBLOCKZ

Theo Neeskens, Uniface Consultant and general problem solver at ITBLOCKZ
07 Nov 2018
4:44 pm
Avatar
gianni
Member
Forum Posts: 357
Member Since:
01 Oct 2012
sp_UserOfflineSmall Offline

Theo Neeskens said

I just tought it would be evident to have this in componenttostruct, as it will often deliver a much smaller struct that is faster to process.
… 

Agreed. It’s part of those (many) small things making the difference…

Gianni

Forum Timezone: Europe/Amsterdam

Most Users Ever Online: 131

Currently Online:
27 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

ulrich-merkel: 1890

Iain Sharp: 680

Theo Neeskens: 371

gianni: 357

Adrian Gosbell: 318

istiller: 299

rogerw: 272

Knut: 229

lalitpct: 197

Arjen van Vliet: 184

Member Stats:

Guest Posters: 3

Members: 10982

Moderators: 0

Admins: 6

Forum Stats:

Groups: 1

Forums: 62

Topics: 2323

Posts: 10052

Newest Members:

greentipodent1976, NicolasHib, gipipufen1981, Alfredvax, Lesterpioto, crystalst3, otogsa12, Ramonmaw, harolddz1, Lariskawo

Administrators: admin: 23, diseli: 1045, Nico Peereboom: 84, richiet: 406, Mike Taylor: 38, JanCees: 39