我目前正在創建一個在線詞典。使用Javascript搜索和顯示來自XML文件的信息
我從字典存儲這樣的信息的XML文檔:
<?xml version="1.0" encoding="UTF-8"?>
<dictionary>
<norman>
<entry>A 1. the male or positive principle, yang 2. convex, raised 3.interjection ofresponse 4. interjection of fear S. vocative particle 6. a tooth in the Manchuscript A A an interjection of casual response </entry>
<entry>A I BUKDAN the outside edge of a piece of folded paper </entry>
<entry>A JIJUN I ACANGGA a bronze identification token with raised characters used togain admittance to a city at night </entry>
<entry>A JILGAN a yang tone in music A FA SERE ONGGOLO see afanggala </entry>
<entry>A SI a sound used for driving chickens or birds </entry>
<entry>A TA (onom.) the sound of a commotion ABA 1. hunt, battue 2. where
</norman>
</dictionary>
我的HTML看起來像這樣:
<input type="text" name="entry" id="input">
<br />
<input type="submit" value="Submit" onClick="searchXML()">
<br />
<br />
<div id="results">
</div>
我希望用戶能夠搜索詞像「JIJUN」,然後返回每個條目(整行)與該單詞在其中並顯示在「結果」DIV
我的主要問題是我不知道如何去實現用javascript來解決這個問題,一個正確的方向將是非常有幫助的,一個完整的答案會很棒。我已經在堆棧交換中使用過其他例子,但沒有太多幫助。
謝謝
解析XML與JavaScript是沒有樂趣。嘗試以某種JSON格式獲取數據。 – Daniel
你的XML文件有多大,你在做這個前端還是你可以使用節點? –
@DanielKobe截至目前我的XML文件是〜1MB,我正在做這個前端,我不熟悉節點 – user3186749