PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Xml
oleobject loo_CarNode
integer li_NumAttr
integer li_Horsepower
integer i
li_Success = 0
loo_Xml = create oleobject
li_rc = loo_Xml.ConnectToNewObject("Chilkat.Xml")
if li_rc < 0 then
destroy loo_Xml
MessageBox("Error","Connecting to COM object failed")
return
end if
// The sample input XML is available at http://www.chilkatsoft.com/data/car.xml
li_Success = loo_Xml.LoadXmlFile("car.xml")
if li_Success <> 1 then
Write-Debug loo_Xml.LastErrorText
destroy loo_Xml
return
end if
// Navigate to the "car" node, which is the 1st child:
loo_CarNode = loo_Xml.FirstChild()
// Get the value of the "model" attribute:
Write-Debug "model = " + loo_CarNode.GetAttrValue("model")
// Get the value of the "hp" attribute as an integer:
li_Horsepower = loo_CarNode.GetAttrValueInt("hp")
Write-Debug "horsepower = " + string(li_Horsepower)
// Iterate over the attributes and show the name/value of each:
li_NumAttr = loo_CarNode.NumAttributes
i = 0
do while i < li_NumAttr
Write-Debug loo_CarNode.GetAttributeName(i) + ": " + loo_CarNode.GetAttributeValue(i)
i = i + 1
loop
destroy loo_CarNode
destroy loo_Xml