Four Js Development Tools Forum

Discussions by product => Genero BDL => Topic started by: Shawn G. on September 10, 2009, 03:31:48 am



Title: XML DomNodes evaluating Attribute data type
Post by: Shawn G. on September 10, 2009, 03:31:48 am
I'm using an Informix DB v11.50.FC2 with Genero BDL 2.11. While reading the attribute values in a Dom Node, I'm trying to compare one with another attribute value. eg. whether $lhs > $rhs, where $lhs,$rhs are the attribute values. But, without knowing the data type of the attribute value, it is difficult to compare correctly. eg. 1000>300 but "1000" < "300". Or,"31/01/08" > "01/01/09". Is there a way to determine the data type in Genero BDL? Thanks.


Title: Re: XML DomNodes evaluating Attribute data type
Post by: Reuben B. on September 10, 2009, 04:27:07 am
Hi Shawn,

Whoever supplies you the .xml file should be able to give you a schema for it that indicates what datatypes are expected as attribute values.

It is generaly not possible to look at a value and determine "the" datatype. e.g. is 100 a CHAR(3), or an INTEGER.

What most Genero users will have though is a library function such as is_date(x), is_number(x) that returns TRUE/FALSE.  These routines are written using techniques similar to the code below, that is attempt to assign the unknown datatype (stored as a string) to a variable of that datatype.  If the operation succeeds then it is possible that value is that datatype and hence RETURN TRUE, if the assignment fails then we know that value is not an example of that datatype.


FUNCTION is_date(s)
DEFINE s STRING
DEFINE d DATE
   WHENEVER ANY ERROR CONTINUE
   LET d = s
   RETURN (STATUS=0)
   WHENEVER ANY ERROR ...  # set back to previous state
END FUNCTION

FUNCTION is_date(s)
DEFINE s STRING
DEFINE d DATE
   TRY
      LET d = s
      RETURN TRUE
   CATCH
      RETURN FALSE
   END TRY
END FUNCTION


Title: Re: XML DomNodes evaluating Attribute data type
Post by: Shawn G. on September 10, 2009, 04:45:47 am
Thank you Reuben.


Title: Re: XML DomNodes evaluating Attribute data type
Post by: Frank G. on September 10, 2009, 09:05:51 am
Hi,

  Have you ever tried with the GWS package and its XML and serializer APIs ? You can for instance use the fglwsdl -x tool to generate 4GL variables according to XML schemas, and then use the serializer functions to convert a XML file into that 4GL variables. Notice also that the serializer will care about the datatype specified in the XML schema when doing the conversion.

Regards,
Frank


Title: Re: XML DomNodes evaluating Attribute data type
Post by: Shawn G. on September 10, 2009, 10:59:28 am
Hi Frank - I will research your idea and determine if it can be applied in my program. Thanks.


Title: Re: XML DomNodes evaluating Attribute data type
Post by: Shawn G. on September 11, 2009, 06:45:07 am
Frank - this is new to me - i'm not sure what you mean...


Title: Re: XML DomNodes evaluating Attribute data type
Post by: Frank G. on September 15, 2009, 09:19:08 am
Hi Shawn,

  I don't know your exact needs, but if you have trouble to convert XML attributes into 4GL variables, maybe that the GWS extension can help. Actually the GWS package is not only to support Web Services, but it provides all necessary APIs to handle XML and convert it into 4GL. It's why I suggested to convert the XML Schema you have to follow by using the fglwsdl tool with option -x. It will generate a 4GL variable representing your XML Schema, and keeping all necessary piece of information to convert correctly any XML document in that 4GL variable. Then in your application you won't have to access to your XML document via a DomNode, but directly by that generated 4GL variable, once you have called the xml.Serializer.DomToVariable function.

Hope it is more clear now,
If you have more precise questions, don't hesitate.

Frank