提问人:John Mercier 提问时间:7/11/2023 更新时间:7/14/2023 访问量:35
无法从 xsd 生成 VMAP 类
Cannot generate VMAP classes from xsd
问:
我在 github 上使用 maven-jaxb2-plugin 启动了一个项目,从 vmap xsd 生成 VMAP 类。
我遇到的问题似乎是 xsd 本身的问题。
[ERROR] Error while parsing schema(s).Location [ file:/projects/generate-vmap-example/src/main/resources/vmap.xsd{144,70}].
org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'vast:VAST' to a(n) 'element declaration' component.
一切似乎都设置正确。vmap.xsd 声明 vast 命名空间并导入 vast xsd。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:vmap="http://www.iab.net/videosuite/vmap" xmlns:vast="http://www.iab.net/videosuite/vast" targetNamespace="http://www.iab.net/videosuite/vmap" attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.iab.net/videosuite/vast" schemaLocation="vast3_draft.xsd"/>
此处使用 VAST 元素。
<xs:complexType name="VASTAdData_type">
<xs:sequence>
<xs:element ref="vast:VAST" minOccurs="1" maxOccurs="1"/>
</xs:sequence>
</xs:complexType>
是否应该修改 vmap xsd 才能使其正常工作?为什么找不到 VAST 元素?
您可以在此处查看完整的项目。
答:
0赞
mamift
7/12/2023
#1
在 vast3_draft.xsd 文件中,如果将以下属性添加到根元素:xsd:schema
- xmlns=“http://www.iab.net/videosuite/vast”
- targetNamespace=“http://www.iab.net/videosuite/vast”
所以它变成了这样:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified" xmlns="http://www.iab.net/videosuite/vast" targetNamespace="http://www.iab.net/videosuite/vast">
然后,当再次发生类生成时,vmap.xsd 应正确解析。
出现此错误的原因是,在 vmap.xsd 架构中,它使用 的值导入 vast3_draft.xsd,并且该命名空间不在 vast3_draft.xsd 架构中的任何位置。元素始终需要属性,因此导入的架构也需要此属性。targetNamespace
http://www.iab.net/videosuite/vast
xs:import
targetNamespace
我猜因为它的文件名中有“草稿”一词,所以架构本身可能不完整。如果获得架构的新更新版本,则必须再次编辑架构文件,如果它在元素中仍然没有上述属性。xs:schema
评论
0赞
John Mercier
7/12/2023
感谢您的帮助,我会尝试一下。草稿文件实际上是这个版本的官方文件。IAB的人就是这样奇怪。
0赞
John Mercier
7/12/2023
这实际上会导致一个新错误,我知道vast3_draft.xml它自己可以生成类。[ERROR] Error while parsing schema(s).Location [ file:/projects/generate-vmap-example/src/main/resources/vast3_draft.xsd{21,118}]. org.xml.sax.SAXParseException: src-resolve: Cannot resolve the name 'AdSystem_type' to a(n) 'type definition' component.
0赞
John Mercier
7/13/2023
我还添加了 xmlns 属性并得到了SAXParseException: A class/interface with the same name "com.github.moaxcp.vast.vmap.ExtensionsType" is already in use. Use a class customization to resolve this conflict.
0赞
mamift
7/13/2023
@JohnMercier 你能更新 github 项目,这样我就可以亲眼看到你所做的更改吗?
0赞
John Mercier
7/14/2023
是的,它已更新
评论