从 POJO 生成 SOAP XML
您好,出于日志记录和调试目的,我需要以 SOAP XML 形式将 spring bean 的输入 POJO 存储在数据库中。你能帮我看看我可以使用哪个库吗?你有一些如何从 POJO 对象创建 SOAP XML 的代码示例吗?我尝试使用 javax.xml.soap.* 生成 SOAP Envelope、Header 和 Body,并使用 JAXB 从 POJO 生成 xml。 javax.xml.soap.* 工作正常,但我对 POJO xml 中的命名空间有问题。有没有办法自动生成命名空间?例如...
我没有命名空间的输出是
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<z:getClientDetail xmlns:z="my.package">
<client>
<adresses>
<city>Praha</city>
<houseNumber>1455</houseNumber>
<street>Hudeckova</street>
</adresses>
<adresses>
<city>Brno</city>
<houseNumber>44</houseNumber>
<street>Tupolevova</street>
</adresses>
<firstName>Standa</firstName>
<lastName>Vrana</lastName>
</client>
</z:getClientDetail>
但带有名称空间的正确输出是
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<z:getClientDetail xmlns:z="my.package">
<java:client xmlns:java="my.package.dto">
<java:adresses>
<java:city>Praha</city>
<java:houseNumber>1455</houseNumber>
<java:street>Hudeckova</street>
</java:adresses>
<java:adresses>
<java:city>Brno</city>
<java:houseNumber>44</houseNumber>
<java:street>Tupolevova</street>
</java:adresses>
<java:firstName>Standa</firstName>
<java:lastName>Vrana</lastName>
</java:client>
</z:getClientDetail>
谢谢P。
Hello for loging and debuging purpose I need to store input POJO of spring bean in DB in SOAP XML form. Can you help me which library i can use and do you have some code examples how to create SOAP XML from POJO object. I try to use javax.xml.soap.* to generate SOAP Envelope, Header and Body, and JAXB for generating xml from POJO. javax.xml.soap.* works fine, but i have problem with namespaces in POJO xml. Is there way to generate namespaces automaticaly? For example...
My output without namespaces is
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<z:getClientDetail xmlns:z="my.package">
<client>
<adresses>
<city>Praha</city>
<houseNumber>1455</houseNumber>
<street>Hudeckova</street>
</adresses>
<adresses>
<city>Brno</city>
<houseNumber>44</houseNumber>
<street>Tupolevova</street>
</adresses>
<firstName>Standa</firstName>
<lastName>Vrana</lastName>
</client>
</z:getClientDetail>
But correct output with namespace is
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<z:getClientDetail xmlns:z="my.package">
<java:client xmlns:java="my.package.dto">
<java:adresses>
<java:city>Praha</city>
<java:houseNumber>1455</houseNumber>
<java:street>Hudeckova</street>
</java:adresses>
<java:adresses>
<java:city>Brno</city>
<java:houseNumber>44</houseNumber>
<java:street>Tupolevova</street>
</java:adresses>
<java:firstName>Standa</firstName>
<java:lastName>Vrana</lastName>
</java:client>
</z:getClientDetail>
Thanks P.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用包级别注释
javax.xml.bind.annotation.XmlSchema
来完成此操作。然后,JAXB 将从给定命名空间中带注释的包中的 pojo 生成 XML。如果您愿意,也可以使用
javax.xml.bind.annotation.XmlType
注释或在逐个字段的基础上使用javax.xml.bind.annotation。 XmlElement
注释。You can use the package level annotation
javax.xml.bind.annotation.XmlSchema
to accomplish this. JAXB will then generate the XML from the pojo's in the annotated package in the given namespace.If you would prefer you can also do this on a class-by-class basis using the
javax.xml.bind.annotation.XmlType
annotation or on a field-by-field basis using thejavax.xml.bind.annotation.XmlElement
annotation.为什么要以 SOAP XML 形式将数据存储在 DB 中?
要从 POJO 对象创建 SOAP XML,您可以手动编写所有静态部分并从 POJO 中放置所有动态值,如下所示。
前任:
Why do you want to store data in DB in SOAP XML form?
And to create SOAP XML from POJO object, you can write manually all the static part and put all dynamic values from POJO like below.
Ex: