当前位置:  开发笔记 > 编程语言 > 正文

使用默认命名空间时,无法解组编组的文档

如何解决《使用默认命名空间时,无法解组编组的文档》经验,为你挑选了0个好方法。

我设置了一个显示我的问题的回购:https://github.com/Waxolunist/stackoverflow.34392476

我尝试解组一个简单的xml文档:



     
         
         
             lokal
         
         bec811a9807a8c8da403d70b9b5e22ad
     

这是我从以下代码获得的文档:

    Document document = new Document();
    Export export = new Export();
    ExportKopf exportKopf = new ExportKopf();
    exportKopf.setQuelle("lokal");
    export.setExportKopf(exportKopf);
    ExportInhalt exportInhalt = new ExportInhalt();
    export.setExportInhalt(exportInhalt);
    export.setSchemaVersion("bec811a9807a8c8da403d70b9b5e22ad");
    document.setExport(export);

    JAXBContext jaxbContext = JAXBContext.newInstance(Document.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(document, System.out);

文件如下:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "document", namespace = "http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx")
public class Document {

    @XmlElement(name = "Export", namespace = "urn:adcubum:Syrius")
    private vo.dom.common_service.modul_bl.syrius.Export export;

}

package-info.java

@XmlSchema(
namespace = "urn:adcubum:Syrius",
xmlns = {
    @XmlNs(prefix = "for", namespaceURI = "http://www.adcubum.com/wsdl/global/callout/syrius/modul_bl/doc/service/documentrenderer/forwktbx"),
    @XmlNs(prefix = "", namespaceURI = "urn:adcubum:Syrius")
}, 
elementFormDefault = XmlNsForm.UNQUALIFIED)

当我尝试解组时,我没有得到数据映射:

    JAXBContext jaxbContext = JAXBContext.newInstance(Document.class);
    Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();

    InputStream is = this.getClass().getResourceAsStream("/requests/document_simple3.xml");
    XMLInputFactory factory = XMLInputFactory.newInstance();
    XMLStreamReader xmlsr = factory.createXMLStreamReader(is);

    Document document = unmarshaller.unmarshal(xmlsr, Document.class).getValue();

ExportKopf和ExportInhalt返回null.

而是跟随xml工作.唯一的区别是名称空间前缀:



    
        
        
            lokal
        
        bec811a9807a8c8da403d70b9b5e22ad
    

我正在使用eclipselink moxy.

我需要更改什么,以便解组已编组的文档.

推荐阅读
赛亚兔备_393
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有