简体   繁体   English

带有XMLBeans数据绑定的Axis2-从具有anyType的XSD架构生成的Java客户端出现问题

[英]Axis2 with XMLBeans data binding - Problem with a java client generated from a XSD schema with anyType

I have generated a client using Axis2 framework with XMLBeans as the data binding method. 我已经使用Axis2框架和XMLBeans作为数据绑定方法生成了一个客户端。 The XSD schema is the following: XSD架构如下:
<xsd:schema>
<xsd:element name="profile" type="anyType"/>
</xsd:schema>

The java object generated which takes part of the SOAP request contains getter and setter methods that allow to get and set the profile. 生成的Java对象(包含SOAP请求)包含getter和setter方法,这些方法允许获取和设置概要文件。 Here is the method signature: requestDocument.setProfile(XmlObject profile); 这是方法签名: requestDocument.setProfile(XmlObject profile);

The problem is that even if that I have to pass several nodes as the profile and not a valid XML document, but XMLObject expects a XML document with a root node. 问题是,即使我必须传递多个节点作为概要文件,也不传递有效的XML文档,但是XMLObject期望具有根节点的XML文档。

I need to pass: 我需要通过:
<accounts></accounts>
<payees></payees>

Actually, the service I use expects those nodes but did not constrains them in the schema. 实际上,我使用的服务期望这些节点,但没有将它们约束在架构中。 Thus, I can't add another root node because even if the service won't throw any exceptions, the profile won't be usable. 因此,我无法添加另一个根节点,因为即使该服务不会引发任何异常,该配置文件也将无法使用。

XMLBeans already adds the underlying XML tree, I mean the profile node in the request document. XMLBeans已经添加了基础XML树,我的意思是请求文档中的profile节点。 Thus, I can't use it as a root node. 因此,我不能将其用作根节点。 if I add a root node, the following XML will be created 如果添加根节点,将创建以下XML
<profile> <profile></profile> </profile>

And I want the document be formatted as follow: 我希望文档的格式如下:
<profile>
<accounts></accounts> <payees></payees>
</profile>

I prefer not modifying the schema of the service. 我更喜欢不修改服务的架构。 I would want to know if there is a way with Axis2/XMLBeans to tackle this issue. 我想知道Axis2 / XMLBeans是否可以解决此问题。

I find a solution that is probably a workaround and not the clean way it should be done. 我发现一个解决方案可能是一种解决方法,而不是应采用的干净方法。 Instead of setting the profile with an XMLObject as follow: 代替使用XMLObject设置配置文件,如下所示:
requestDocument.setProfile(XmlObject profile);
I used org.w3c.dom.Node object to create the profile content. 我使用org.w3c.dom.Node对象创建配置文件内容。 See below: 见下文:
1. Create the elements org.w3c.dom.Element to be added to the profile: 1.创建要添加到概要文件中的元素org.w3c.dom.Element
Element accountsElt = profileDocument.createElement("accounts");
Element payeesElt = profileDocument.createElement("payees");
2. Create an empty profile in the document to be send to the service, note that the object is auto generated: 2.在要发送到服务的文档中创建一个空的配置文件,请注意该对象是自动生成的:
requestDocument.addNewProfile();
3. Get the empty profile and add children to its root node: requestDocument.getProfile().getDomNode().appendChild(accountsElt); 3.获取空的配置文件并将子级添加到其根节点: requestDocument.getProfile().getDomNode().appendChild(accountsElt); requestDocument.getProfile().getDomNode().appendChild(payeesElt);

I hope it helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM