Automic Workload Automation

Expand all | Collapse all

XML DOM functions for attributes

  • 1.  XML DOM functions for attributes

    Posted 12-04-2018 09:08 AM

    With XML_GET_ATTRIBUTE & XML_SET_ATTRIBUTE, one can get or set the name of an XML attribute whose name is already known. However, I was not able to find any XML DOM functions akin to these, but for attributes:

     

    I have not been able to find a way to list and print the names and values of all attributes, even if one does not know their names ahead of time. Is there a way to do this, short of parsing the whole XML text?



  • 2.  Re: XML DOM functions for attributes

    Posted 12-05-2018 09:34 AM

    I came up with a hack to list the attributes of a node:

    1. Save the current node to a temporary XML VARA
    2. Use PREP_PROCESS_VAR_XML to extract from the temporary XML VARA the name/value pairs of each attribute.

     

    ! Write current DOM node to temporary XML VARA
    :SET &XML_VARA_Name# = UC0.TEMP_&$RUNID#.VARA_XML
    :SET &XML_VARA_Key# = "Temp_XML"
    :SET &XML_VARA_String# = XML_TO_STRING(&XML_DOM#)
    :PUT_VAR &XML_VARA_Name#,&XML_VARA_Key#,&XML_VARA_String#

    ! Grab attribute list
    :DEFINE &XML_Attr#,STRING,2
    :SET &XML_Atrr_Delim# = ";"
    :SET &XML_VARA_Xpath# = './*/@*/fn:concat(fn:name(.),"&XML_Atrr_Delim#",.)'
    :SET &XML_Attr_Hnd# = PREP_PROCESS_VAR_XML(&XML_VARA_Name#, &XML_VARA_Key#, &XML_VARA_Xpath#)
    :SET &Attr_Counter# = 0
    :PROCESS &XML_Attr_Hnd#
    :  SET &Attr_Counter# = &Attr_Counter# + 1
    :  IF &Attr_Counter# = 1
    :    PRINT "Atrributes"
    :    PRINT "  Name            Value"
    :  ENDIF
    :  SET &XML_Attr_Line# = GET_PROCESS_LINE(&XML_Attr_Hnd#,0)
    :  FILL &XML_Attr#[] = STR_SPLIT(&XML_Attr_Line#,&XML_Atrr_Delim#)
    :  SET &XML_Attr_Name#  = &XML_Attr#[1]
    :  SET &XML_Attr_Value# = &XML_Attr#[2]
    :  SET &XML_Attr_Name# = STR_PAD(&XML_Attr_Name#," ",16,LEFT)
    :  PRINT "  &XML_Attr_Name#&XML_Attr_Value#"
    :ENDPROCESS
    :CLOSE_PROCESS &XML_Attr_Hnd#

     

    This is a bit of a kludge, but it works. I put it in a JOBI and include it wherever I need to read element attributes. I create the temporary VARA at the beginning of the whole process, and remove it only after all of the steps that might need to use it have completed.



  • 3.  Re: XML DOM functions for attributes

    Posted 12-05-2018 09:47 AM

    There should be a way to read and set attributes whose names are not known ahead of time, so I created an idea for this:

    XML DOM functions for attributes