如何根据标记名称读取条目标记内的所有标记,并使用java将其值存储在hashmap中

时间:2016-02-18 09:02:02

标签: java xml

以下是xml代码,我希望根据标记名称获取值,该标记名称存在于条目标记下,并将其作为键值对存储在hashmap中

<entry xmlns="http://www.w3.org/2005/Atom">
    <title>Isra쭩쳳 doden drie Palestijnse aanvallers</title>
    <updated>2016-02-17T17:13:11.477Z</updated>
    <rights>This material may not be published</rights>
    <content type="text/plain" xml:lang="nl">Isra쭩쳳 doden drie Palestijnse aanvallers</content>
    <apcm:ContentMetadata xmlns:apcm="http://ap.org/schemas/03/2005/apcm">
        <apcm:Priority Numeric="4" Legacy="r" />
        <apcm:ConsumerReady>TRUE</apcm:ConsumerReady>
        <apcm:ByLine>Paul Gabel</apcm:ByLine>
        <apcm:HeadLine>Isra쭩쳳 doden drie Palestijnse aanvallers</apcm:HeadLine>
        <apcm:OriginalHeadLine>Isra쭩쳳 doden drie Palestijnse aanvallers</apcm:OriginalHeadLine>
        <apcm:Keywords>Westoever</apcm:Keywords>
        <apcm:Cycle>BC</apcm:Cycle>
        <apcm:Selector>-----</apcm:Selector>
        <apcm:SlugLine>Westoever 2016/02/17 22:43:58</apcm:SlugLine>
        <apcm:MediaType>Text</apcm:MediaType>
        <apcm:SubjectClassification System="Editorial" Authority="AP Category Code" Value="DUT" Id="DUT" />
        <apcm:Property Name="EntitlementMatch" Id="urn:publicid:ap.org:product:45147" Value="All Text for Elasticsearch" />
        <apcm:Property Name="SequenceNumber" Value="InSequence" Id="236167493" />
        <apcm:FirstCreated>2016-02-14T15:43:48Z</apcm:FirstCreated>
    </apcm:ContentMetadata>
    <apnm:NewsManagement xmlns:apnm="http://ap.org/schemas/03/2005/apnm">
        <apnm:ManagementId>urn:publicid:ap.org:f02232ade7f4394d95337af4b9200c47</apnm:ManagementId>
        <apnm:ManagementSequenceNumber>0</apnm:ManagementSequenceNumber>
    </apnm:NewsManagement>
</entry>

1 个答案:

答案 0 :(得分:0)

使用JaxB。用于XML绑定的Java体系结构(JAXB)提供了一种快速方便的方法来绑定XML模式和Java表示,使Java开发人员可以轻松地在Java应用程序中合并XML数据和处理函数。

example