2011-10-05 84 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