0

I wonder whether someone could help me please.

I have an xml file which is made up of approx 22,000 OS Grid References, an extract is shown below.

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
    - <Root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    - <Row>
      <Name>Deserted medieval village</Name> 
      <NGR>SS 00000 11111</NGR> 
      </Row>

What I need to do for each 'NGR' is convert it to a Lat & Lng co-ordinate. If I were to do this manually I'd key the NGR onto a HTML form I have and use the following Javascript code (from nearby.org.uk) on a click event to convert it. I will then save it to a table in a mySQL database.

function converttolatlng() {
    var gr = document.getElementById('osgridref').value;

    var osgb = new GT_OSGB();


    if (osgb.parseGridRef(gr)) {
        var wgs84 = osgb.getWGS84();

        document.getElementById('osgb36lat').value = wgs84.latitude;
        document.getElementById('osgb36lon').value = wgs84.longitude;
    }
    else {
        document.getElementById('osgb36lat').value = "n/a";
        document.getElementById('osgb36lon').value = "n/a";
    }

}

Because I have so many, I'd like to be able to run this conversion automatically and from what I've read on the Internet I think the best way is to run the xml through PHP, but I must admit I'm not sure where to begin.

I just wondered if someone could perhaps take a look at this please and show me what I would need to do to create the extraction process.

Sincere thanks

1 Answer 1

1

Have you considered using an XML database, since your input document is XML? The code would then look like:

for $row in doc("input.xml")//Row
let $coordinates := parseGridRef($row/NGR)
(: assuming parseGridRef implements the conversion :)
return some-insertion-function("some-collection-name",
  <entry>
    <name>{$row}</name>
    <latitude>{$coordinates[1]}</latitude>
    <longitude>{$coordinates[2]}</longitude>
  </entry>)
1
  • Hi, many thanks for taking the time to reply to my post. No, I hadn't thought of using an XMl database because the majority of the records will be created from user input within HTMl files. It's only 1 file that I'll add to my database each month. Kind regards. Commented Oct 5, 2011 at 17:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.