Post by jstone71 on Dec 14, 2016 15:25:03 GMT -5
Hi, I'm using the Linux version of Run Basic as a prototyping tool while I write functional requirements for a web app that will be coded in Python. I'm using the XML parser to process weather data sourced from the UK's Met Office. However, attribcount() appears to be returning results for the element that precedes it in the document tree. For example, the count for the REP element is given as 2, but this is the count for the parent PERIOD element not the REP element. Consequently, I can't access any of the REP element's 10 attribute/value pairs. Am I doing something wrong?
Code is as follows and I've attached a sample XML file.
Sample output:
Key: DV Value: | Attributes: 0 | Element count: 2 (actual number of attributes = 2)
Key: Location Value: | Attributes: 2 | Element count: 1 (actual number of attributes = 7)
dataDate, 2016-12-14T16:00:00Z
type, Forecast
Key: Period Value: | Attributes: 7 | Element count: 5 (actual number of attributes = 2)
i, 354282
lat, 52.5938
lon, -2.1326
name, WOLVERHAMPTON WANDERERS F.C.
country, ENGLAND
continent, EUROPE
elevation, 128.0
Key: Rep Value: 720 | Attributes: 2 | Element count: 4 (actual number of attributes = 10)
type, Day
value, 2016-12-14Z
Key: Rep Value: 900 | Attributes: 2 | Element count: 4
type, Day
value, 2016-12-14Z
Key: Rep Value: 1080 | Attributes: 2 | Element count: 4
type, Day
value, 2016-12-14Z
Key: Rep Value: 1260 | Attributes: 2 | Element count: 4
type, Day
value, 2016-12-14Z
test.xml (3.78 KB)
Can anyone help?
Thanks.
Code is as follows and I've attached a sample XML file.
open "test.xml" for input as #test
a = lof(#test)
doc1$ = input$(#test, a)
close #test
xmlparser #doc, doc1$
print #doc key$()
call displayElements #doc
end
sub displayElements #xmlDoc
count = #xmlDoc elementCount()
for x = 1 to count
#elem = #xmlDoc #element(x)
print "Key: "; #elem key$();
value$ = #elem value$()
attrib = #xmlDoc attribcount()
print " Value: "; value$; " | Attributes: "; attrib; " | Element count: "; count
for y = 1 to attrib
print #xmlDoc attribkey$(y);", "; #xmlDoc attribvalue$(y)
next y
print ""
call displayElements #elem
next x
end sub
Sample output:
Key: DV Value: | Attributes: 0 | Element count: 2 (actual number of attributes = 2)
Key: Location Value: | Attributes: 2 | Element count: 1 (actual number of attributes = 7)
dataDate, 2016-12-14T16:00:00Z
type, Forecast
Key: Period Value: | Attributes: 7 | Element count: 5 (actual number of attributes = 2)
i, 354282
lat, 52.5938
lon, -2.1326
name, WOLVERHAMPTON WANDERERS F.C.
country, ENGLAND
continent, EUROPE
elevation, 128.0
Key: Rep Value: 720 | Attributes: 2 | Element count: 4 (actual number of attributes = 10)
type, Day
value, 2016-12-14Z
Key: Rep Value: 900 | Attributes: 2 | Element count: 4
type, Day
value, 2016-12-14Z
Key: Rep Value: 1080 | Attributes: 2 | Element count: 4
type, Day
value, 2016-12-14Z
Key: Rep Value: 1260 | Attributes: 2 | Element count: 4
type, Day
value, 2016-12-14Z
test.xml (3.78 KB)
Can anyone help?
Thanks.