getattr


Purpose
Get the value of an attribute.
Synopsis
function getattr(doc:xmldoc, n:integer, name:string):text
function getboolattr(doc:xmldoc, n:integer, name:string):boolean
function getintattr(doc:xmldoc, n:integer, name:string):integer
function getrealattr(doc:xmldoc, n:integer, name:string):real
function getstrattr(doc:xmldoc, n:integer, name:string):string
Arguments
doc 
Document to use
Node number (must be an element)
name 
Name of the attribute
Return value
The value of the attribute or an empty string, 0 or false depending on the expected type.
Example
The following code extract prints the contents of 'name' (leftbound in a 10 character space) and the attributes 'id' of all 'employee' nodes, and the 'id' of their parent node.
  declarations
    DB: xmldoc
    AllEmployees: list of integer
  end-declarations

  getnodes(DB, "personnelList/region/employee", AllEmployees)
  forall(p in AllEmployees)
    writeln(textfmt(getvalue(DB, getnode(DB, p, "name")), -10),  
            "(ID: ", getattr(DB,p,"id"), ") ",
            "region: ", getattr(DB, getparent(DB, p), "id"))
 
Output produced by this code will look as follows:
Lisa      (ID: L234) region: EMEA
James     (ID: J876) region: APAC
Sarah     (ID: S678) region: AM 
Further information
1. Values of attributes are stored as text objects: the first version of the routine returns a reference to the object containing the attribute value. Modifying this text will also alter the attribute value. Using one of the alternative versions of this routine allows to avoid having to perform a type conversion.
2. A default value (empty string, 0 or false) is returned if the requested attribute is not defined. Use function testattr to check whether a given node has a particular attribute.
Related topics
setattr, testattr, getfirstattr
Module
mmxml


If you have any comments or suggestions about these pages, please send mail to support@fico.com.

© Copyright 2001-2013 Fair Isaac Corporation. All rights reserved.