简体   繁体   English

Java中的XML解析以获取键,值对吗?

[英]XML Parsing in java to get it in Key, Value Pair?

There are many XML Parsing technique are there which I am not aware yet. 有很多我还不知道的XML解析技术。 I want to parse the XML (Form Data) and get the form output data in Key, Value pair. 我想解析XML(表单数据)并获取键,值对中的表单输出数据。 Which XML parsing technique makes it easy to get the values in key value pair for the following XML format, 哪种XML解析技术可以轻松获取以下XML格式的键值对中的值,

<?xml version="1.0" encoding="UTF-8"?>
<metadata>
<control for="9bd2f8fd2421eb0b0a410feaa1f482c50551486a" name="first-name" type="input" datatype="string">
                <resources lang="en">
                        <label>First Name</label>
                        <help />
                        <hint>Your first or given name
                        </hint>
                        <alert />
                </resources>
                <resources lang="fr">
                        <label>Prénom</label>
                        <help />
                        <hint>
                                Votre prénom
                        </hint>
                                <alert />
                </resources>
                <value>Rahul</value>
        </control>
        <control for="8532f26e19a5b33200f56bb839c5f3aa2fa3a25f" name="last-name" type="input" datatype="string">
                <resources lang="en">
                        <label>Last Name</label>
                        <help />
                        <hint>Your last name</hint>
                        <alert />
                </resources>
                <resources lang="fr">
                        <label>Nom de famille</label>
                        <help />
                        <hint>Votre nom de famille</hint>
                        <alert />
                </resources>
                <value>Sharma
                </value>
        </control>
</metadata> 

Note I need to capture only values with English Language. 注意我只需要捕获英语值。 For the above XML I need the output as follows, 对于上述XML,我需要如下输出:

First Name - Rahul
Last Name - Sharma 

This might push to the right direction: 这可能会推向正确的方向:

Which is the best library for XML parsing in java 这是Java中XML解析的最佳库

And to capture the values in English, you would have to employ natural language processing to recognize which language the text you've captured using the xml parser. 为了捕获英语中的值,您将必须使用自然语言处理来识别使用xml解析器捕获的文本是哪种语言。 Luckily, you can use libraries for identifying english sentences. 幸运的是,您可以使用库来识别英语句子。 Here is a post outlining java libraries to identify the language of text: 这是概述Java库以识别文本语言的文章:

How to detect language of user entered text? 如何检测用户输入文字的语言?

Then after removing the text that is not english, you can go through in retrieving the dictionary. 然后,在删除非英语文本之后,您就可以检索字典了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM