2011-10-05 81 views
0

我想知道是否有人可以帮助我。通过PHP和JavaScript转换XML功能

我有一个xml文件,它由大约22,000个OS网格引用组成,下面显示了一个摘录。

<?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> 

我需要为每个“NGR”做的是将其转换为纬度& LNG坐标。如果我要手动执行此操作,我会将NGR键入我拥有的HTML表单中,并在点击事件中使用以下Javascript代码(来自nearby.org.uk)进行转换。然后我将它保存到mySQL数据库中的表中。

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"; 
    } 

} 

因为我有这么多,我想能够自动在运行这个转换是什么,我在网上看了我认为最好的方式是通过PHP运行XML,但我必须承认我不知道从哪里开始。

我只是想知道是否有人可以看看这个请给我看看我需要做什么来创建提取过程。

真诚的感谢

回答

1

你有没有使用XML数据库,因为你的输入文档是XML考虑?代码然后看起来像:

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>) 
+0

嗨,非常感谢您花时间回复我的文章。不,我没有想过使用XMl数据库,因为大部分记录都是通过HTMl文件中的用户输入创建的。每个月只有1个文件会添加到我的数据库中。亲切的问候。 – IRHM