XSD "property already defined"



我正试图使用jaxb编译一些Veracode提供的.xsd文件

"detailedreport.xsd"正在引发以下错误:

[ERROR] Property "Vulnerabilities" is already defined. Use <jaxb:property> to resolve this conflict.
line 930 of file:detailedreport.xsd
[ERROR] The following location is relevant to the above error
line 936 of detailedreport.xsd

当我查看XSD文件时,我发现Vulnerabilities既是attr又是类型:

<xs:complexType name="Component">
<xs:annotation>
<xs:documentation>
The element describe the details of vulnerable component.
* file_paths: File paths of the component.
----->       * vulnerabilities : Vulnerabilities of the component.
* violated_policy_rules: Violated policy rules of the component.
* component_id: The id of the component.
* file_name: File name of the component.
----->       * vulnerabilities: Number of vulnerabilities available in the component.
* max_cvss_score: Max cvss_score of the component.
* library: Library name of the component.
* version: Version of the component.
* vendor: Vendor name of the component.
* description: Description about component.
* blacklisted: Component's blacklisted status.
* new: Component added newly.
* added_date: Component's added_date.
* component_affects_policy_compliance: COmponent's policy violation status.
* licenses: Contains license details of the component.
</xs:documentation>
</xs:annotation>
<xs:sequence>
<xs:element name="file_paths" minOccurs="0" maxOccurs="1" type="tns:FilePathList"/>
<xs:element name="licenses" minOccurs="0" maxOccurs="1" type="tns:LicenseList"/>
----->      <xs:element name="vulnerabilities" minOccurs="0" maxOccurs="1" type="tns:VulnerabilityList" />
<xs:element name="violated_policy_rules" minOccurs="0" maxOccurs="1" type="tns:ViolatedRuleList" />
</xs:sequence>
<xs:attribute name="component_id" type="xs:string" use="required"/>
<xs:attribute name="file_name" type="xs:string" use="required"/>
<xs:attribute name="sha1" type="xs:string" use="required"/>
----->  <xs:attribute name="vulnerabilities" type="xs:integer" use="required"/>
<xs:attribute name="max_cvss_score" type="xs:string" use="required"/>
<xs:attribute name="library" type="xs:string" use="required"/>
<xs:attribute name="version" type="xs:string" use="required"/>
<xs:attribute name="vendor" type="xs:string" use="required"/>
<xs:attribute name="description" type="xs:string" use="required"/>
<xs:attribute name="blacklisted" type="xs:string"/>
<xs:attribute name="new" type="xs:string"/>
<xs:attribute name="added_date" type="xs:string"/>
<xs:attribute name="component_affects_policy_compliance" type="xs:string"/>
</xs:complexType>

以下是他们发布的xsd:https://analysiscenter.veracode.com/resource/detailedreport.xsd

根据我的理解,我需要创建一个detailedreport.xjb文件,并(作为输出状态(设置一个<jaxb:property>,以将vulnerabilities整数属性转换为类似vulnerabilityCount的属性。

我创建了详细的报告.xjb:

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb">
<!-- Used to avoid the duplicate element/attribute name conflict -->
<jaxb:bindings node="//xsd:attribute[@name='vulnerabilities']">
<jaxb:property name="vulnerabilityCount"/>
</jaxb:bindings>
</jaxb:bindings>

但是我的xpath是错误的:

[ERROR] XPath evaluation of "//xsd:attribute[@name='vulnerabilities']" results in empty target node
line 10 of file: detailedreport.xjb
  1. 我是否走上了正确的道路
  2. 感谢任何xpath的帮助

应该再提供一个引用架构位置的bindins元素:

<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jxb:extensionBindingPrefixes="xjc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemalocation="http://java.sun.com/xml/ns/jaxb 
http://java.sun.com/xml/ns/jaxb"
>
<jxb:bindings schemaLocation="PATH_TO_THE_SCHEMA" node="/xs:schema">
<jxb:bindings node="//xs:attribute[@name='vulnerabilities']">
<jxb:property name="vulnerabilityCount"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>

路径可以是相对于xjb文件的,例如:schemaLocation="../detailedreport.xsd"

相关内容

最新更新