Tech Tip: Getting all XML attribute names and values into arrays
PRODUCT: 4D | VERSION: 11 | PLATFORM: Mac & Win
Published On: September 23, 2011
For XML DOM parsing in 4D, here is a utility method that populates two text arrays with the attribute names and values for XML node.
` Method: DOM_XML_ATTR_TO_ARRAYS ` Parameters ` $1 - XML node reference ` $2 - Pointer to a text array (attribute names) ` $3 - Pointer to a text array (attribute values) C_TEXT($1;$xmlnode_t) C_POINTER($2;$xmlattr_name_atp) C_POINTER($3;$xmlattr_value_atp) C_TEXT($name_t;$value_t) C_LONGINT($attributeCount_l;$index_l) If (Count parameters>=3) $xmlnode_t:=$1 $xmlattr_name_atp:=$2 $xmlattr_value_atp:=$3 $attributeCount_l:=DOM Count XML attributes($xmlnode_t) ARRAY TEXT($xmlattr_name_atp->;$attributeCount_l) ARRAY TEXT($xmlattr_value_atp->;$attributeCount_l) For ($index_l;1;$attributeCount_l) DOM GET XML ATTRIBUTE BY INDEX($xmlnode_t;$index_l;$name_t;$value_t) $xmlattr_name_atp->{$index_l}:=$name_t $xmlattr_value_atp->{$index_l}:=$value_t End for End if |
Example calls:
DOM_XML_ATTR_TO_ARRAYS($xml_reference_t;->$xml_attr_name_at;->$xml_attr_value_at) |