首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“已定义的属性”

“已定义的属性”
EN

Stack Overflow用户
提问于 2020-02-24 21:59:02
回答 1查看 620关注 0票数 0

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

"detailedreport.xsd“正在抛出此错误:

代码语言:javascript
复制
[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,也是一个类型:

代码语言:javascript
复制
    <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的属性。

我创建了detailedreport.xjb:

代码语言:javascript
复制
<?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是错误的:

代码语言:javascript
复制
[ERROR] XPath evaluation of "//xsd:attribute[@name='vulnerabilities']" results in empty target node
  line 10 of file: detailedreport.xjb

  1. 我甚至在正确的路径上
  2. 任何xpath帮助都很感谢
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-25 07:28:24

还应该提供另一个引用模式位置的bindins元素:

代码语言:javascript
复制
<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"

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60384525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档