`
bigboy
  • 浏览: 167772 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

org.xml.sax.SAXException: Invalid element

阅读更多

今天开发项目遇到一个问题,简单记录下,希望能帮到遇到同样问题的同学

 

我使用Axis1.4开发webservice客户端,客户端代码如下:

 Service service = new Service();

Call call;

try {

call = (Call)service.createCall();

call.setTargetEndpointAddress(d2Url);

 

QName qn = new QName("", "CMSID");

call.addParameter(qn, XMLType.SOAP_STRING, ParameterMode.IN);

 

QName qn2 = new QName("", "CorrelateID");

call.addParameter(qn2, XMLType.SOAP_STRING, ParameterMode.IN);

 

QName qn3 = new QName("", "ContentMngXMLURL");

call.addParameter(qn3, XMLType.SOAP_STRING, ParameterMode.IN);

 

call.setReturnClass(ContentDeployReqResponse.class);

QName mapping = new QName("iptv", "ContentPreloadReqResponse");

 

call.registerTypeMapping(ContentDeployReqResponse.class, mapping,

new BeanSerializerFactory(ContentDeployReqResponse.class, mapping), 

new BeanDeserializerFactory(ContentDeployReqResponse.class, mapping));

 

call.setOperationName(new QName("iptv", "ContentPreloadReq"));

return call;

} catch (ServiceException e) {

e.printStackTrace();

}catch(Exception e){

e.printStackTrace();

}

return null;

 

ContentDeployReqResponse类代码如下:

import java.io.Serializable;

 

import javax.xml.bind.annotation.XmlAccessType;

import javax.xml.bind.annotation.XmlAccessorType;

import javax.xml.bind.annotation.XmlElement;

 

@XmlAccessorType(XmlAccessType.FIELD)

public class ContentDeployReqResponse implements Serializable{

 

/**

*/

private static final long serialVersionUID = -6709028467973715698L;

 

@XmlElement(name = "ErrorDescription")

private String errorDescription;

 

@XmlElement(name = "ResultCode")

private int resultCode;

 

 

public int getResultCode() {

return resultCode;

}

 

public void setResultCode(int resultCode) {

this.resultCode = resultCode;

}

 

public String getErrorDescription() {

return errorDescription;

}

 

public void setErrorDescription(String errorDescription) {

this.errorDescription = errorDescription;

}

 

 

}

 

 

调用服务端后返回的xml如下:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">

<S:Body>

<ns2:ContentPreloadReqResponse xmlns:ns2="iptv">

<return>

<ResultCode>0</ResultCode>

<ErrorDescription>success</ErrorDescription>

</return>

</ns2:ContentPreloadReqResponse>

</S:Body>

</S:Envelope>

Axis在解析xml为ContentDeployReqResponse  时出现以下错误:

[2013-12-19 17:51:24,234 ERROR] Exception: org.apache.axis.client.Call.invoke(Call.java:2469)

org.xml.sax.SAXException: Invalid element in opt.fonsview.cmm.ws.ContentDeployReqResponse - ResultCode

at org.apache.axis.encoding.ser.BeanDeserializer.onStartChild(BeanDeserializer.java:258)

at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)

at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165)

at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141)

at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:236)

at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384)

at org.apache.axis.client.Call.invoke(Call.java:2467)

at org.apache.axis.client.Call.invoke(Call.java:2366)

 

at org.apache.axis.client.Call.invoke(Call.java:1812)

 

首先想到的是将ContentDeployReqResponse  中的属性首字母大写,发现还是出现以上问题,查看源代码,Axis用到的是javax.bean相关类来生成ContentDeployReqResponse  类信息,我猜测应该是为了跟java规范保持一致,所以在保存属性名的时候是将首字母小写,而返回的xml中首字母是大写,导致出错。

 

采用第二种方法,改写Axis相关源码,替换jar包中文件,运行成功,改写的源文件为org.apache.axis.encoding.ser.BeanDeserializer 的onStartChild方法   

改写之前:

if (propDesc == null) {

            // look for a field by this name. 

        propDesc = (BeanPropertyDescriptor) propertyMap.get(localName);

 

 

}

改写之后:

if (propDesc == null) {

            // look for a field by this name.

        for(Iterator iter = propertyMap.keySet().iterator(); iter.hasNext();){

        String key = (String)iter.next();

        if(key.equalsIgnoreCase(localName)){

        propDesc = (BeanPropertyDescriptor) propertyMap.get(key);

        break;

        }

        }

 

        }

 

开发过程中还遇到一个问题未解决:Axis在解析返回的XML时耗费的时间过长,达10分钟之久,发现问题出在InputStream的read方法上,什么原因?欢迎碰到相同的同学一起探讨

 

附件为修改后的axis jar包

 

分享到:
评论
3 楼 g24317854 2017-08-08  
感谢,遇到同样的问题,确实是返回首字母大写的问题
2 楼 lvweifang 2017-02-15  
差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评差评 
1 楼 chen_juns 2016-04-18  
谢谢博主,按照你方案已解决

相关推荐

    java调用.net发布的webservice(asmx)

    封装了java调用.net的websevice接口,解决了soapaction报错和server not identified错误,使用soap1.1协议。

    java调用net开发的webservice实例

    javax.wsdl.WSDLException: WSDLException: faultCode=PARSER_ERROR: Problem parsing '- WSDL Document -'.: org.xml.sax.SAXParseException: The element type "p" must be terminated by the matching end-tag ...

    Matlab高阶谱分析(HOSA)工具箱及安装方法

    org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'area'. One of '{MathWorksID, type}' is expected. 运行hosaver: Warning: Could not find an exact ...

    SAX.java 操作xml文件

    SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件SAX.java 操作xml文件

    Wrox.Beginning.Xml.2ed-Xml.Schemas.Soap.Xslt.Dom.And.Sax.2.0.rar

    SAX的工作原理简单地说就是对文档进行顺序扫描,当扫描到文档(document)开始与结束、元素(element)开始与结束、文档(document)结束等地方时通知事件处理函数,由事件处理函数做相应动作,然后继续同样的扫描,...

    Javase-6.0_中文API_HTML(最新更新)

    javase 中文API 最新版 ******************************* JavaTM 2 Platform Standard Ed.... 所有类软件包 java.applet java.awt ...javax.lang.model.element ...javax.xml ...org.xml.sax.helpers

    jdk 中文版

    java jdk api帮助文档中文版 JavaTM Platform Standard Ed. 6 所有类 软件包 java.applet java.awt java.awt.color java.awt.datatransfer java.awt.dnd ...javax.lang.model.element ...org.xml.sax.helpers

    java SE API

    JavaTM 2 Platform Standard Ed. 5.0 所有类 软件包 java.applet java.awt java.awt.color java.awt.datatransfer java.awt.dnd java.awt.event ...javax.xml javax.xml.datatype ...org.xml.sax.helpers

    BeRoot, 特权升级项目 Windows/Linux/Mac.zip

    BeRoot, 特权升级项目 Windows/Linux/Mac BeRoot项目BeRoot项目是一个发布工具,用于检查常见的以找到一种方法来升级我们的特权。它已经被添加到 pupy 项目作为一个post开发模块( 所以它将在内存中执行而不需要触摸...

    XML Programming Bible

    Chapter 6: Parsing XML with SAX . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 Chapter 7: XSLT Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 Chapter 8: XSL ...

    2020-10-29日自己保存华为短信开发包smproxy.rar

    好多版本是会报错的,[Fatal Error] :24:28: An ... org.xml.sax.SAXParseException: An invalid XML character (Unicode: 0xd863) was found in the element content of the documen.,这个版本是纠正过后重新打包做的

    J2EE.v1.3.1.API.chm

    v 1.3 API Specification Compiled to .CHM by 貀vind Stegard Packages javax.activation javax.ejb javax.ejb.spi ...c.dom org.xml.sax org.xml.sax.ext org.xml.sax.helpers

    htmlparser

    org.htmlparser.sax.Attributes.class org.htmlparser.sax.Feedback.class org.htmlparser.sax.Locator.class org.htmlparser.sax.XMLReader.class org.htmlparser.scanners.CompositeTagScanner.class org....

    解析XML所需的jar sax.jar

    解析XML所需的jar sax.jar

    dom.sax.pull解析

    Java解析XML的三种方式 ...Ø 2、SAX(org.xml.sax) Ø SimpleAPI for XML,以事件的形式通知程序,对Xml进行解析。 Ø 3、XMLPULL(org.xmlpull.v1) Ø 类似于SAX方式,程序以“拉取”的方式对Xml进行解析。

    xmlrpc android

    android调用xmlrpc的方法会出现错误 javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities。 本文通过自己的方法来...

    android layout XML解析错误的解决方法

    org.xml.sax.SAXParseException: PI must not start with xml (position:unknown xm@3:5 in java.io.InputStreamReader@43e4b480) 经过多次查找确认XML语法没错误。 问题原因: 为XML文件第一行格式错误,仔细修改第

    SAX_XML.rar_XML SAX_sax xml_xml

    使用Sax解析XML,演示了如何使用SAX接口来解析xml,有主要方法的介绍。

    1.ASP.NET.2.0.XML.高级编程(第3版) [1/3]

    \r\n 1.1.2 基本术语 \r\n 1.1.3 XML文档的组成部分 \r\n 1.2 XML技术 \r\n 1.2.1 DTD \r\n 1.2.2 XDR \r\n 1.2.3 XSD \r\n 1.2.4 XSLT \r\n 1.2.5 XML DOM \r\n 1.2.6 XPath \r\n 1.2.7 SAX \r\n 1.2.8 ...

Global site tag (gtag.js) - Google Analytics