我目前正在创建一个在线词典。使用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