- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 wsimport 创建了一个肥皂客户端,我需要将消息中字符串字段内的 xml 数据发送到网络服务器。我知道我实际上并不需要在 Web 服务调用中使用 cdata,但 Web 服务需要此字段位于 cdata 标记中。
问题是如何做到这一点。
为了从 wsdl 生成代码,我使用 jaxws-maven-plugin。在 Maven 配置中我使用绑定(bind)文件
bindingFiles
binding Filebinding.xjb /bindingFile
/bindingFiles
jxb:bindings version="2.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:uniface:applic:services:BRF_IN"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb">
<jxb:globalBindings generateElementProperty="false"/>
<jxb:bindings scd="//element::tns:DATA">
<jxb:javaType
name="String"
parseMethod="de.xyz.CdataConverter.unmarshal"
printMethod="de.xyz.CdataConverter.marshal"
/>
</jxb:bindings>
marshal/unmarschal 看起来像这样:
public class CdataConverter {
private static final Pattern PATTERN = Pattern.compile("((?<=\\<\\!\\[CDATA\\[)[\\S\\s]+(?=\\]\\]\\>))");
private static final String CDATA_START = "<![CDATA[";
private static final String CDATA_END = "]]>";
private final static Logger logger =
Logger.getLogger(LgTestServer.class.getName());
public static String marshal(String input) {
if (input == null) {
return null;
}
PropertyConfigurator.configure(".\\log4j.properties");
logger.info("input --------------------->>>>>>>>\n" + input);
return CDATA_START + input + CDATA_END;
}
public static String unmarshal(String cdatainput) {
if (cdatainput == null) {
return null;
}
Matcher matcher = PATTERN.matcher(cdatainput);
if (matcher.find()) {
return matcher.group();
}
return cdatainput.trim();
}
这样我在数据字段中得到一个 ![CDATA[ 但 xml 是这样编码的
<![CDATA[<?xml version="1.0" encoding="UTF-8"?>
现在我在这里找到了这个(如何使用 jaxb 进行 cdata): http://odedpeer.blogspot.de/2010/07/jaxb-sun-and-how-to-marshal-cdata.html
但我不明白如何使用 Maven 插件和 wsimport 来做到这一点。我的意思是,我无法对其进行编码,它必须以任何方式进行配置。
你有什么想法如何做到这一点吗?
最佳答案
注释 @XmlCDATA
( read more ) 可以由 JAXB Annotate Plugin 自动生成。我使用的绑定(bind)如下。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
jaxb:version="2.1"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox">
<!--Choose one-->
<!--wsimport--><jaxb:bindings schemaLocation="service.wsdl#types?schema1" node="/xs:schema">
<!--wsdl2java--><jaxb:bindings schemaLocation="service.wsdl#types1" node="/xs:schema">
<jaxb:bindings node="//xs:complexType[@name='RegisterPaymentRequest']/xs:sequence/xs:element[@name='returnURL']">
<annox:annotate target="field">
<annox:annotate annox:class="org.eclipse.persistence.oxm.annotations.XmlCDATA"/>
</annox:annotate>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
jaxws-maven-plugin (wsimport) 定义:
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>generate-sources-service</id>
<phase>generate-sources</phase>
<configuration>
<sourceDestDir>${project.basedir}/src/main/java</sourceDestDir>
<bindingDirectory>${project.basedir}/src/main/resources</bindingDirectory>
<bindingFiles>
<bindingFile>binding.xjb</bindingFile>
</bindingFiles>
<wsdlDirectory>${project.basedir}/src/main/resources</wsdlDirectory>
<wsdlFiles>
<wsdlFile>service.wsdl</wsdlFile>
</wsdlFiles>
<xjcArgs>
<xjcArg>-Xannotate</xjcArg>
</xjcArgs>
</configuration>
<goals>
<goal>wsimport</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
</plugin>
cxf-codegen-plugin (wsdl2java) 定义:
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.5.5</version>
<executions>
<execution>
<id>generate-sources-service</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.basedir}/src/main/java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>
${project.basedir}/src/main/resources/service.wsdl
</wsdl>
<extraargs>
<extraarg>-xjc-Xannotate</extraarg>
<extraarg>-b</extraarg>
<extraarg>
${project.basedir}/src/main/resources/binding.xjb
</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>annotate</artifactId>
<version>0.4.1.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>org.eclipse.persistence.moxy</artifactId>
<version>2.4.0</version>
</dependency>
</dependencies>
</plugin>
关于jax-ws - jax-ws/wsimport 中的 cdata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9893531/
这个问题在这里已经有了答案: What does in XML mean? (13 个答案) 关闭 8 年前。 我不熟悉 XML 及其相关技术。 这个 CDATA 标签总是在开头,然后是一些东西
我遇到了这种困难的情况,我需要在另一个 CDATA 标签中使用 CDATA 标签。不过,这种情况很容易解释。 我有以下东西: ]]> 出于显示目的,我也需要将我的 Javascript 包装
我是 Blogger 博客用户。我曾经看到一个在 CDATA 标记内定位脚本的模板,如下所示: /**/ 虽然,我之前看到过类似的代码,如下所示: // 唯一不同的是/*
我很确定节可以在 XHTML5 中使用,但是 HTML5 呢? 最佳答案 CDATA structure 根本不是针对 HTML 的,它是针对 XML 的。 人们有时会在 XHTML 里面使用它们 s
我正在尝试删除字符串中的所有 [.*],但不删除 ![CDATA[xxx]]。我期待以下结果 """![CDATA[please remove[macro]]]""" .replaceAll(
不允许在 内堵塞。这是可以理解的。 现在,我必须在 中传输用户输入的数据堵塞。恶意用户可能会输入 或两者兼而有之。 问题是:处理这种情况的首选方法是什么? 剥离 ? 用空格替换它? 用错误消息打
我有一个定义元素“密码”的 XSD。我想允许任何角色存在。目前,我将元素定义为 xs:string用户必须转义字符串(例如 myP&ssword )或将其包含在 CDATA 标记中(例如 )
我在解析 XML 时遇到以下异常 org.xml.sax.SAXParseException: The processing instruction target matching "[xX][mM]
我正在尝试使用 powershell 读取 rss 提要,但无法在提要中提取 cdata 部分 这是提要的片段(为了节省空间,剪掉了一些项目): ... text 2011-11-28T
XML文档中的所有文本均会被解析器解析 只有CDATA 区段中的文本会被解析器忽略 PCDATA - 被解析的字符数据 XML解析器通常会解析 XML 文档中所有的文本 当某个XML 元素被解
我需要使用 Javascript 清除该文本 block 的部分内容: Lorem Ipsum is simply dummy text of the printing and typesetting
我看到了 solution让 XmlSerializer 输出 CDATA 部分,但是是否可以根据另一个值有条件地实现这一点? 下面的代码演示了我想要的结果: enum LogItemType {
我正在 Angular 应用程序中进行 soap 调用。 我需要为其中一个调用的有效载荷部分传递 CDDATA angular.forEach(contactsCollection, function
请帮帮我 在终端中: C no longer supported in regex; marked by / 我的文件 perl 中的代码 if ($html =~ //) 解决这个问题的最佳方法是什
我得到一个包含 CDATA 的字符串,我想删除它。 Input : "" Output I want : Hello World 我想获取 之间的所有数据和 并将其添加到
最近,我正在创建一个模块来将谷歌再营销标签添加到网上商店。根据文档,我已经为不同类型的页面(产品、类别、购物车等)准备了 google_tag_params。一切顺利,直到客户使用 Chrome 的
我试图在描述字段中创建 CDATA 部分,但失败了。代码非常简单,但在生成的 XML 中没有出现 CDATA 部分!! Node de = document.createElement("descri
这个问题是由开发人员 Michael Rys 相当激进地拒绝将 CDATA 部分的解析包含到 FOR XML PATH 中引起的,因为 "There is no semantic difference
您好,我这里有一个 CDATA 示例 和 我的 CDATA 正则表达式无法识别这个 "])*"]]>" 这也行不通 "][^\]]*[\]]{2,})*">" 有人可以给我一个 的正则表达式吗?
我经常使用内联 Javascript,通常是在我制作的 WordPress 主题中。我没有听说过在 // 中包装内联 Javascript直到几个月前,几年来我一直在以相当的能力水平做这件事。 我四处
我是一名优秀的程序员,十分优秀!