Using Jdom to develop e-dictionary of loanwords in Japanese

Source: Internet
Author: User
Tags query reference root directory
Dom (author: Chen Guangjia)

This article does not intend to elaborate on the jdom of this Third-party Toolkit for rapid XML development or to cover all Jdom's approach to XML, since the articles and materials are already rich, Only want to be able to use the Jdom for specific development of the case to have not used or just started to use the jdom of friends a little bit of the form of a knowledge of the API.

Project Overview and selection of XML APIs--jdom API
I am in the publishing house recently to the Chinese and Japanese Korean text reference books into electronic materials, in the development of teaching multimedia and hope to be able to develop web-based electronic dictionary (first to carry out the development of Japanese loanwords dictionary), the latter project by my responsibility. Since the project will be japplet as the client's choice, and the thesaurus material is provided as an XML document, I began to collect Java data on XML processing. I first saw Jdom's introduction on the JAVA.SUN.COM, after visiting the Jdom org site and reading a few articles about Jdom, I decided to use Jdom to complete the XML processing in the project.

The JDOM API version is the JDOM Beta6 that is downloaded from JDOM org, and the latest version is JDOM Beta7, which has been greatly improved compared to BETA6,BETA7. (Download the latest version of Jdom)
I use JBUILDER3 for development, Jdom needs to be added into its Java libraries as an added class library. My jdom is installed in the root directory of e disk, configured as follows:

Name:jdom
CLASS Path:e:\jdom6bt\jdom-b6\build\jdom.jar
SOURCE Path:e:\jdom6bt\jdom-b6\src\java.zip
DOC Path:e:\jdom6bt\jdom-b6\build\jdom.jar
But JBUILDER5 has direct support for JDOM, and the JDOM API is already embedded in its Java libraries, which makes it easier for us to use JDOM.

XML document structure of Word library data
The document structure of XML in this project is relatively simple, with <dict> as the root, the main body in the Japanese Katakana entry as the unit (<word>), respectively, the following <spell><prop><mean> Each child element corresponds to the katakana spelling, the spelling of foreign words, and the Chinese interpretation of the contents:


In this project, the XML used is not generated using jdom, but it is also easy to generate the same XML structure using Jdom, and here is a simple implementation snippet:


Because you want to support multiple languages, XML is encoded in UTF-8, where you need to note that Jdom's xmloutputer default output character is encoded as UTF-8, and if you want to output a different encoding, you can use Outputter.setencoding () Set (please refer to http://www.jdom.org/docs/faq.html). In this FAQ only described output encoding, but did not explain jdom in the input processing XML encoding requirements, I began to use the XML document is encoded in UCS-2, but Jdom does not work correctly, the error occurred:

Org.jdom.JDOMException:Error in Building:the name ' is not legal for jdom/xml elements:xml names ' be null or cannot
When UTF-8 encoding is used, the jdom processing of the XML works correctly, and is not known to be related to Unicode encoded high and low bytes in the Java internal Unicode encoding for foreign files (for processing general Unicode files, when entering, You need to swap the file for high and low byte so that Java can handle it correctly, I haven't found the information yet.

using Jdom to realize the entry query function of electronic dictionaries
To implement the query function is mainly two, ① by Japanese katakana fuzzy query, ② by foreign words fuzzy query:

(The fuzzy query here only shows the simple first character of the same & character number of the same search law) here only the Jdom-related statements are selected for display:


adding child elements to an XML document using Jdom
In order to add the Korean dimension to the XML data document, we need to add the-koreamean to the XML document, and add the child element to the same as the XML document described above, just to give a simple example of a jdom document output, And to mention some of the problems I have encountered in dealing with.

Program Fragment:


Results:

I first use the Filewrieter class output, the output effect is to output the XML file, but there is not all the content of the output of the situation, the last part of the entry is omitted, the use of FileWriter class output file length is limited by the reason.

The output is completely correct by using the FileOutputStream class for a new output.

Summary
Jdom has rich, powerful XML processing ability, this article only uses the example limited demonstration several commonly used functions, believed that as Jdom formally accepts becomes the Java specification request, its application is more and more widespread, the reader will see more systematic to the Jdom application example.

reference materials
JDOM Org Web site
Jsrs:java specification Requests detail--JSR 102 JDOM 1.0
Easy Java/xml integration with jdom--by Jason Hunter and Brett McLaughlin Http://www.javaworld.com/javaworld/jw-05-2000/ Jw-0518-jdom.html
http://www.ibiblio.org/xml/slides/nypc/jdom/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.