Polylines from XML
Here’s an example showing how to read polyline data from an XML file.
Here’s the XML file.
The method is similar to the processing of markers from an XML file, except now each line contains several points. When the data is processed we need to use a nested loop. The outer loop steps through the lines. The inner loop steps through the points for that line.
I’ve put “colour” and “width” attributes in the line entries in the XML file, and used them to control the colour and width of the polylines.
It’s possible to have marker and polyline information in the same XML file. The ‘getElementsByTagName(“marker”)’ bit only reads the markers and the ‘getElementsByTagName(“line”)’ bit only reads the lines.
- An XML file can only have one top level element. In the example, everything is inside the <markers> . . . </markers>. Don’t try to put the markers in <markers> . . . </markers> and the lines in a separate <lines> . . . </lines> element.
- The potential pitfalls from Part 3 apply to polylines as well as markers