如何使用JAX解析XML

时间:2016-03-17 14:52:08

标签: java xml jaxb

我有以下XML文件,我需要使用JAXB将其解析为Java类。 我无法理解,我怎么解析这样的行:

<project id="237" name="***"/>

XML的完整版本:                                           10387                                                                                                                                                   ***

                <start_date>2016-03-17</start_date>
                <due_date/>
                <done_ratio>30</done_ratio>
                <estimated_hours/>
                <custom_fields type="array">
                    <custom_field id="3" name="***">
                        <value>***</value>
                    </custom_field>
                    <custom_field id="16" name="***">
                        <value/>
                    </custom_field>
                    <custom_field id="33" name="***">
                        <value>***</value>
                    </custom_field>
                    <custom_field id="25" name="***">
                        <value>***</value>
                    </custom_field>
                    <custom_field id="26" name="***">
                        <value/>
                    </custom_field>
                    <custom_field id="27" name="***">
                        <value/>
                    </custom_field>
                    <custom_field id="47" name="***">
                        <value/>
                    </custom_field>
                    <custom_field id="48" name="***">
                        <value/>
                    </custom_field>
                </custom_fields>
                <created_on>***</created_on>
                <updated_on>***</updated_on>
                <closed_on/>
            </issue>
            <issue>
                <id>***</id>
                <project id="229" name="***"/>
                <tracker id="44" name="***"/>
                <status id="24" name="***"/>
                <priority id="4" name="***"/>
                <author id="23" name="***"/>
                <assigned_to id="26" name="***"/>
                <subject>***</subject>
                <description>...</description>
                <start_date>***</start_date>
                <due_date/>
                <done_ratio>20</done_ratio>
                <estimated_hours/>
                <custom_fields type="array">...</custom_fields>
                <created_on>***</created_on>
                <updated_on>***</updated_on>
                <closed_on/>
            </issue>
            ... e.t.c
        </issues>

我有一个unmarshal例外,无法理解。

1 个答案:

答案 0 :(得分:0)

为了解析XML和HTML,Jsoup是一个有用且简单的库。

http://jsoup.org/