具有 XMLBeans 数据绑定的 Axis2 - 从具有任何类型的 XSD 架构生成的 java 客户端的问题

发布于 2024-09-29 07:27:01 字数 853 浏览 2 评论 0 原文

我使用 Axis2 框架和 XMLBeans 作为数据绑定方法生成了一个客户端。 XSD 架构如下:
<代码>

生成的作为 SOAP 请求一部分的 java 对象包含允许获取和设置配置文件的 getter 和 setter 方法。这是方法签名: requestDocument.setProfile(XmlObject profile);

问题是,即使我必须传递多个节点作为配置文件而不是有效的 XML 文档,但 XMLObject 需要一个带有根节点的 XML 文档。

我需要通过:
<账户>

实际上,我使用的服务需要这些节点,但并未将它们限制在架构中。因此,我无法添加另一个根节点,因为即使服务不会抛出任何异常,配置文件也将无法使用。

XMLBeans 已经添加了底层 XML 树,我的意思是请求文档中的配置文件节点。因此,我不能将它用作根节点。如果我添加根节点,将创建以下 XML
<代码><个人资料> <个人资料>

我希望文档的格式如下:
<个人资料>
<帐户> <收款人>

我不想修改服务的架构。我想知道 Axis2/XMLBeans 是否有办法解决这个问题。

I have generated a client using Axis2 framework with XMLBeans as the data binding method.
The XSD schema is the following:
<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. Here is the method signature:
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.

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. Thus, I can't use it as a root node. if I add a root node, the following XML will be created
<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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

涙—继续流 2024-10-06 07:27:01

我找到了一个可能是解决方法的解决方案,而不是应该完成的干净方式。
而不是使用 XMLObject 设置配置文件,如下所示:
requestDocument.setProfile(XmlObject 配置文件);
我使用 org.w3c.dom.Node 对象来创建配置文件内容。见下文:
1. 创建要添加到配置文件中的元素 org.w3c.dom.Element
Element accountElt = profileDocument.createElement("accounts");
Element payeesElt = profileDocument.createElement("payees");
2. 在要发送到服务的文档中创建一个空配置文件,请注意该对象是自动生成的:
requestDocument.addNewProfile();
3. 获取空配置文件并将子节点添加到其根节点:
requestDocument.getProfile().getDomNode().appendChild(accountsElt);
requestDocument.getProfile().getDomNode().appendChild(payeesElt);

我希望它有帮助。

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:
requestDocument.setProfile(XmlObject profile);
I used org.w3c.dom.Node object to create the profile content. See below:
1. Create the elements org.w3c.dom.Element to be added to the profile:
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:
requestDocument.addNewProfile();
3. Get the empty profile and add children to its root node:
requestDocument.getProfile().getDomNode().appendChild(accountsElt);
requestDocument.getProfile().getDomNode().appendChild(payeesElt);

I hope it helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文