Sample code for 30+ languages & platforms
Xbase++

Methods for Getting Attributes

See more XML Examples

Demonstrates some methods for getting attribute name/values.

The input XML, available at http://www.chilkatsoft.com/data/car.xml, is this:

<root>
    <car color="black" make="mercedes" model="C350" hp="302" engine="v6" type="sedan">Mercedes Benz C350</car>
</root>

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oXml
LOCAL oCarNode
LOCAL nNumAttr
LOCAL nHorsepower
LOCAL i

nSuccess := 0

oXml := CreateObject("Chilkat.Xml")

//  The sample input XML is available at http://www.chilkatsoft.com/data/car.xml
nSuccess := oXml:LoadXmlFile("car.xml")
IF (nSuccess != 1)
    ? oXml:LastErrorText
    oXml:destroy()
    RETURN
ENDIF

//  Navigate to the "car" node, which is the 1st child:
oCarNode := oXml:FirstChild()

//  Get the value of the "model" attribute:
? "model = " + oCarNode:GetAttrValue("model")

//  Get the value of the "hp" attribute as an integer:
nHorsepower := oCarNode:GetAttrValueInt("hp")
? "horsepower = " + Str(nHorsepower)

//  Iterate over the attributes and show the name/value of each:
nNumAttr := oCarNode:NumAttributes

i := 0
DO WHILE i < nNumAttr
    ? oCarNode:GetAttributeName(i) + ": " + oCarNode:GetAttributeValue(i)
    i := i + 1
ENDDO

oCarNode:destroy()

oXml:destroy()