热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

javax.xml.bind.UnmarshalException:意外元素(uri:"",local:"").预期的要素是

如何解决《javax.xml.bind.UnmarshalException:意外元素(uri:"",local:"").预期的要素是》经验,为你挑选了2个好方法。

你可以在这个网站上找到很多像这样的问题,但没有一个问题解决了我的问题.

这是我的XML:




PQAA
ANTHONY1900


我使用XJC编译器创建了Jaxb类,创建的文件如下:

//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
// See http://java.sun.com/xml/jaxb 
// Any modifications to this file will be lost upon recompilation of the source schema. 
// Generated on: 2015.01.13 at 12:15:41 PM IST 
//


package com.dsths.ga.awd.main;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;


/**
 * 

Java class for anonymous complex type. * *

The following schema fragment specifies the expected content contained within this class. * *

 * 
 *   
 *     
 *       
 *         
 *           
 *             
 *               
 *                 
 *                   
 *                     
 *                       
 *                         
 *                           
 *                         
 *                       
 *                     
 *                   
 *                 
 *               
 *             
 *           
 *         
 *       
 *       
 *     
 *   
 * 
 * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "lookupParameters" }) @XmlRootElement(name = "lookupInstances") public class LookupInstances { @XmlElement(required = true) protected LookupInstances.LookupParameters lookupParameters; @XmlAttribute protected String name; /** * Gets the value of the lookupParameters property. * * @return * possible object is * {@link LookupInstances.LookupParameters } * */ public LookupInstances.LookupParameters getLookupParameters() { return lookupParameters; } /** * Sets the value of the lookupParameters property. * * @param value * allowed object is * {@link LookupInstances.LookupParameters } * */ public void setLookupParameters(LookupInstances.LookupParameters value) { this.lookupParameters = value; } /** * Gets the value of the name property. * * @return * possible object is * {@link String } * */ public String getName() { return name; } /** * Sets the value of the name property. * * @param value * allowed object is * {@link String } * */ public void setName(String value) { this.name = value; } /** *

Java class for anonymous complex type. * *

The following schema fragment specifies the expected content contained within this class. * *

     * 
     *   
     *     
     *       
     *         
     *           
     *             
     *               
     *                 
     *               
     *             
     *           
     *         
     *       
     *     
     *   
     * 
     * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "", propOrder = { "lookupParameter" }) public static class LookupParameters { @XmlElement(required = true) protected LookupInstances.LookupParameters.LookupParameter lookupParameter; /** * Gets the value of the lookupParameter property. * * @return * possible object is * {@link LookupInstances.LookupParameters.LookupParameter } * */ public LookupInstances.LookupParameters.LookupParameter getLookupParameter() { return lookupParameter; } /** * Sets the value of the lookupParameter property. * * @param value * allowed object is * {@link LookupInstances.LookupParameters.LookupParameter } * */ public void setLookupParameter(LookupInstances.LookupParameters.LookupParameter value) { this.lookupParameter = value; } /** *

Java class for anonymous complex type. * *

The following schema fragment specifies the expected content contained within this class. * *

         * 
         *   
         *     
         *       
         *     
         *   
         * 
         * 
* * */ @XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "") public static class LookupParameter { @XmlAttribute protected String name; /** * Gets the value of the name property. * * @return * possible object is * {@link String } * */ public String getName() { return name; } /** * Sets the value of the name property. * * @param value * allowed object is * {@link String } * */ public void setName(String value) { this.name = value; } } } }

Unmarshal代码:

    public LookupInstances unmarshallXmlRequest(String xmlReq)
    {
        LookupInstances instances = null;
           try {
            JAXBContext jc = JAXBContext.newInstance( LookupInstances.class );
               Unmarshaller u = jc.createUnmarshaller();
               StringBuffer xmlStr = new StringBuffer( xmlReq );
               StringReader strReader = new StringReader( xmlStr.toString() );
               StreamSource strSource = new StreamSource(strReader);
               Object o = u.unmarshal( strSource );
               instances = (LookupInstances)o;
        } catch (JAXBException e) {

            e.printStackTrace();
        }
        return instances;
    }

我收到了这个错误:

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.pqr.com/awd/rest/v1", local:"lookupInstances"). Expected elements are <{}lookupInstances>

请帮忙.



1> bdoughan..:

以下是一些应该有用的信息:

XML

下面是XML的一部分.有一点需要注意的是xmlns属性.这是一个特殊属性,指的是XML文档中的名称空间限定.


    

下面是另一个具有相同命名空间限定的XML版本:


    

删除xmlns属性时,将删除命名空间限定.以下文件不等同于上述两个.


    

你的错误

javax.xml.bind.UnmarshalException: unexpected element (uri:"http://www.pqr.com/awd/rest/v1", local:"lookupInstances"). Expected elements are <{}lookupInstances>

此错误表示您尚未正确映射命名空间限定.

在JAXB中映射Namesapce资格

JAXB中的命名空间限定是使用包级别@XmlSchema注释完成的.包级别注释进入package-info.java.以下是此课程的完整来源.如果您已有package-info.java源文件,请确保正在编译并与其余类一起打包.

@XmlSchema( 
    namespace = "http://www.pqr.com/awd/rest/v1", 
    elementFormDefault = XmlNsForm.QUALIFIED) 
package your_package;

import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

XML Schema

如果要从XML Schema生成模型,请确保在此处正确定义此命名空间限定.它看起来像:






2> 小智..:

更改

@XmlRootElement(name = "lookupInstances")

@XmlRootElement( namespace = "http://www.pqr.com/awd/rest/v1", name = "lookupInstances")


推荐阅读
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • Java序列化对象传给PHP的方法及原理解析
    本文介绍了Java序列化对象传给PHP的方法及原理,包括Java对象传递的方式、序列化的方式、PHP中的序列化用法介绍、Java是否能反序列化PHP的数据、Java序列化的原理以及解决Java序列化中的问题。同时还解释了序列化的概念和作用,以及代码执行序列化所需要的权限。最后指出,序列化会将对象实例的所有字段都进行序列化,使得数据能够被表示为实例的序列化数据,但只有能够解释该格式的代码才能够确定数据的内容。 ... [详细]
  • baresip android编译、运行教程1语音通话
    本文介绍了如何在安卓平台上编译和运行baresip android,包括下载相关的sdk和ndk,修改ndk路径和输出目录,以及创建一个c++的安卓工程并将目录考到cpp下。详细步骤可参考给出的链接和文档。 ... [详细]
  • XML介绍与使用的概述及标签规则
    本文介绍了XML的基本概念和用途,包括XML的可扩展性和标签的自定义特性。同时还详细解释了XML标签的规则,包括标签的尖括号和合法标识符的组成,标签必须成对出现的原则以及特殊标签的使用方法。通过本文的阅读,读者可以对XML的基本知识有一个全面的了解。 ... [详细]
  • 自动轮播,反转播放的ViewPagerAdapter的使用方法和效果展示
    本文介绍了如何使用自动轮播、反转播放的ViewPagerAdapter,并展示了其效果。该ViewPagerAdapter支持无限循环、触摸暂停、切换缩放等功能。同时提供了使用GIF.gif的示例和github地址。通过LoopFragmentPagerAdapter类的getActualCount、getActualItem和getActualPagerTitle方法可以实现自定义的循环效果和标题展示。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • r2dbc配置多数据源
    R2dbc配置多数据源问题根据官网配置r2dbc连接mysql多数据源所遇到的问题pom配置可以参考官网,不过我这样配置会报错我并没有这样配置将以下内容添加到pom.xml文件d ... [详细]
  • Java太阳系小游戏分析和源码详解
    本文介绍了一个基于Java的太阳系小游戏的分析和源码详解。通过对面向对象的知识的学习和实践,作者实现了太阳系各行星绕太阳转的效果。文章详细介绍了游戏的设计思路和源码结构,包括工具类、常量、图片加载、面板等。通过这个小游戏的制作,读者可以巩固和应用所学的知识,如类的继承、方法的重载与重写、多态和封装等。 ... [详细]
  • 标题: ... [详细]
  • 本文介绍了Python爬虫技术基础篇面向对象高级编程(中)中的多重继承概念。通过继承,子类可以扩展父类的功能。文章以动物类层次的设计为例,讨论了按照不同分类方式设计类层次的复杂性和多重继承的优势。最后给出了哺乳动物和鸟类的设计示例,以及能跑、能飞、宠物类和非宠物类的增加对类数量的影响。 ... [详细]
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • 本文介绍了在处理不规则数据时如何使用Python自动提取文本中的时间日期,包括使用dateutil.parser模块统一日期字符串格式和使用datefinder模块提取日期。同时,还介绍了一段使用正则表达式的代码,可以支持中文日期和一些特殊的时间识别,例如'2012年12月12日'、'3小时前'、'在2012/12/13哈哈'等。 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • MPLS VP恩 后门链路shamlink实验及配置步骤
    本文介绍了MPLS VP恩 后门链路shamlink的实验步骤及配置过程,包括拓扑、CE1、PE1、P1、P2、PE2和CE2的配置。详细讲解了shamlink实验的目的和操作步骤,帮助读者理解和实践该技术。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
author-avatar
轩楼妈
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有