【发布时间】:2013-02-16 14:16:21
【问题描述】:
我有一个 xsd 文件 (yahoo.xsd),我在其中导入另一个 xsd 文件,如下所示:
<xs:import schemaLocation="stock.xsd"/>
<xs:attribute name="lang" type="xs:NCName"/>
stock.xsd 如下所示:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:yahoo="http://www.yahooapis.com/v1/base.rng">
<xs:import namespace="http://www.yahooapis.com/v1/base.rng" schemaLocation="yahoo.xsd"/>
<xs:element name="quote">
<xs:complexType>
<xs:sequence>
<xs:element ref="Symbol"/>
</xs:sequence>
<xs:attribute name="symbol" use="required" type="xs:NCName"/>
</xs:complexType>
</xs:element>
<xs:element name="Symbol" type="xs:NCName"/>
</xs:schema>
当我使用 xjc 进行编译时,我收到以下错误消息:
[错误] 属性“符号”已定义。使用来解决此冲突。
我基本上在 SO (JAXB Compiling Issue - [ERROR] Property "Any" is already defined) 上找到了解决方案,但我无法让它工作。我猜我的 XPath 是错误的。
这是我正在使用的绑定文件:
<bindings xmlns="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.1">
<bindings schemaLocation="yahoo.xsd" version="1.0" >
<!-- rename the value element -->
<bindings node="//xs:element[@name='quote']/xs:complexType/xs:sequence/xs:element[@ref='Symbol']">
<property name="SymbolAttribute"/>
</bindings>
</bindings>
如果我现在使用 xjc -b 进行编译,则表示 XPath 评估结果为空目标节点。
我可能必须重命名 Symbol 定义,然后还要重命名 ref?如何自动执行此操作?
【问题讨论】:
-
您是否尝试将架构添加为基本节点?例如。?
标签: java xml xpath jaxb xml-serialization