Title: properly handle complex Xml data Post by: francesco f. on September 13, 2022, 11:59:07 pm Hi Everyone,
we got a new client that work with complex xml file generated from sap, so we need to load them and in turn create our xml. It's the first time we work in xml with genero and we would like to know what's the best suitable option available right now that can provide flexibility and at the same time be relatively easy to use. we looked into xml.DomDocument and xml.Serializer and both seems to offer cool features. we also throw a cursory glance to https://github.com/FourjsGenero to find some snippets to start from but so far found none. Can someone offer some help please just to put us on the right track? Just to know if there are some real life examples to look from some online repositories So far we tested successfully the validator at https://4js.com/online_documentation/fjs-fgl-manual-html/index.html#fgl-topics/c_gws_XML_DomDocument_class_016.html We would really appreciate Francesco Title: Re: properly handle complex Xml data Post by: Reuben B. on September 15, 2022, 05:58:01 am My advice would be if not familiar with XML to use resources such as what you can find at w3schools https://www.w3schools.com/xml/ and note what they have about DOM https://www.w3schools.com/xml/xml_dom.asp and XPath https://www.w3schools.com/xml/xml_xpath.asp
There are two xml libraries in Genero. The smaller om package http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_Class_om.html has been in Genero since its inception. Its purpose was to provide a means for developers to interact with the AUI Tree http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_DynamicUI_006.html . At beginning of Genero there were no methods to show/hide fields, you did this by yourself manipulating the AUI Tree (XML) as an example such as https://github.com/FourjsGenero/fgl_auitree/blob/master/auitree.4gl#L64, or creating a form, an XML document https://github.com/FourjsGenero/fgl_zoom/blob/master/fgl_zoom.4gl#L1270 The om package is effectively a cut-down xml library as it is just what we felt back in 2000 what was necessary to manipulate the XML AUI Tree. The fully fledged XML package http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_gws_XML_Library_001.html was added to Genero in the 2.10 release in 2007 and has full XML functionality. You will probably find early adopters of Genero met their XML needs and learnt XML by using the om package rather than the xml package, until they found there was something they needed that was only in the XML package e.g.namespaces, complex XPath, working with different types of node, serialization, xslt etc and then it was a case of applying their om skills to xml http://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_gws_OM_to_XML_001.html Otherwise the XML topic is quite broad and you may get a better response if asking a more specific question around what you are trying to do. Wether thats reading an XML document into 4gl variable, or traversing to find and change a particular value in the XML, or creating XML document from a 4gl variable etc. OR perhaps your question might be around some of these examples https://www.w3schools.com/xml/dom_examples.asp and your question might be what is Genero equivalent? Reuben Title: Re: properly handle complex Xml data Post by: francesco f. on September 15, 2022, 11:04:12 am Hi Reuben,
thanks for your reply. I just was looking for some genero example to follow but in the end it seems no too complicated as it seemed at first impression. I'm using the fully fledged xml package. Basically i need to flatten the files and the two methods i'm using the most are a selectByXPath to traverse the dom and arrive where i need and then a series of getElementsByTagName for the tag needed from that node and it seems to work. I Made a two arguments func to which i pass the xpath and the tokenizeble tags. Title: Re: properly handle complex Xml data Post by: Roland W. on September 19, 2022, 02:19:40 pm Hello Francesco,
I'm not sure what your XML file looks like but I've made good experiences with the following approach for flatteing a BMECat file (https://help.sap.com/docs/ARIBA_NETWORK_SUPPLIERS/c8ad7036e6104bfaa33ec523991a6727/65b815e1ae724ce38d02b0fb9faefc7d.html?locale=en-US (https://help.sap.com/docs/ARIBA_NETWORK_SUPPLIERS/c8ad7036e6104bfaa33ec523991a6727/65b815e1ae724ce38d02b0fb9faefc7d.html?locale=en-US)) to a dynamic array. Code
The type t_bmecat is formed recursively from the subelements and is not described here because the full definition is too long. The routines for parsing the individual sub-elements have essentially the same structure as the function above and only need to be adapted with regard to the elements used. Each function will traverse one element from top to bottom and read the contents into the corresponding entry within the array. I'm not sure if this is the best, easiest, most elegant or most performant way but it works quite good. Maybe this small code snippet will help you further. Good luck and kind regards Roland Title: Re: properly handle complex Xml data Post by: francesco f. on September 20, 2022, 03:19:23 pm Hi Roland,
thanks for your time. That's the kind of example i was looking for: practical and clear. At the beginning i was baffled because they send a lot of useless tags (ie 136kb of data for one useful record of product list, can you imagine?) so i had to traverse the dom to reach the points of interest and grab the few tags i needed, so i realized a func with two argument: a selectbyxpath and a series of selectbytagname within loop to grab some of the header tags and some of the rows tags. I bet it's not the most elegant and efficient solution but as long as it does its job i don't care :-))) |