English 中文(简体)
与泽西岛一起解配 xml 标记
原标题:Unmarshalling xml tag with Jersey

我将这个xml:

<?xml version="1.0" encoding="utf-8"?>
 <ProductItem xmlns="http://providers.natinst.com/pdi-rest/1.0/meta/" urn="urn:product-item:910796-76" url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76.xml">
<partNumber>910796-76</partNumber>
<inventoryItemId>560427</inventoryItemId>
<nicInventoryItemId>765430</nicInventoryItemId>
<name />
<description>LABVIEW CORE 2 SELF-PACED ONLINE TRAINING (6 MONTHS ACCESS)</description>
<isCustomerFacing>true</isCustomerFacing>
<itemType>CE</itemType>
<partType>Training Program</partType>
<bookingsClassName />
<bookingsClassCode />
<lifecyclePhase>Released</lifecyclePhase>
<salesClass />
<firstOrderableDate />
<locale>en-US</locale>
<ngpmProductHierarchy />
<productRevisions url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/productRevisions.xml" />
<serviceOptionsForProduct url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/serviceOptionsForProduct.xml" />
<serviceOptionsByService url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/serviceOptionsByService.xml" />
<productFeatures url="http://immix-test2.natinst.com/pdi-rest/1.0/en-US/product-item/910796-76/productFeatures.xml" />
 </ProductItem>

我想得到描述标签 这是我的java代码

package com.ni.apps.elearningrest.client;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;


import javax.xml.bind.annotation.XmlElementWrapper;

@XmlRootElement(name = "ProductItem")
public class DescriptionDTO {

    private String description;
    private String uri;


    @XmlElement(name = "description")
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }               
}

但我不断得到一个“未预料到的元素 ” ( uri: “ http:// provideers. natinst. com/ pdi- rest/ 1.0/ meta/, local : “ productionTrojects ” ) 。 预期元素是 < productionTroject & gt; ” 错误 。 我该怎么做才能解决这个问题?

最佳回答

尝试将命名空间添加到 JAXB 注释 :

问题回答

在您可以指定 XmlRooteEleemant 注释上的命名空间属性时, 我建议使用 注释来指定默认命名空间。

<强势>com/ni/aps/elearningrest/client/package-info.java

@XmlSchema( 
    namespace = "http://providers.natinst.com/pdi-rest/1.0/meta/", 
    elementFormDefault = XmlNsForm.QUALIFIED) 
package com.ni.apps.elearningrest.client;

<强>以获取更多信息





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签