[OpenLayers-Users] Problems parsing simple XML file

Kimball, David (DCR) David.Kimball at state.ma.us
Tue Jan 13 15:08:07 EST 2009


Hi,

I'm trying to load and parse a simple XML file [
http://maps.massgis.state.ma.us/dcr/line_field_lookup.xml ] that is
formatted like this:

<records>
  <record  Objectid="1" Field_name="UNIQUE_ID" English="ID"/>
  <record  Objectid="2" Field_name="TYPE" English="Type"/>
  <record  Objectid="3" Field_name="COMMENTS" English="Comments"/>

[...etcetera...]

</records>

The XML file basically represents a simple 3-column table I need to use.
Through a bunch of sloppy code I have managed to load in the file, but I
can't figure out how to loop through the <record> elements and grab the
'Field_name' and 'English' attributes from each element.  My HTML file
is here [ http://maps.massgis.state.ma.us/dcr/DCR_RoadTrail04.html ] -
the relevant parts are the beginning of the init() function and the
lineXMLloadSuccess() function.  Basically I can't figure out how to use
getElementsByTagNameNS() and getAttributeNS() properly.  Most of the
code I have used so far came from [
http://openlayers.org/dev/examples/xml.html ].

Can anyone help me?  If I could get to the point where I could loop
through the <record> tags and grab an attribute value from each one, I'd
be golden.  I'm guessing that one or two lines of code would do the
trick, I just can't figure it out.

Thanks,

David Kimball

||||||| David Kimball
||||||| GIS Specialist
||||||| MA Department of Conservation and Recreation
||||||| http://www.mass.gov/dcr/stewardship/gis/
||||||| david.kimball at state.ma.us
||||||| 617.626.1447 phone
||||||| 617.626.1349 fax



More information about the Users mailing list