【问题标题】:scalaxb fails when an element and an attribute at the same level having the same name当同一级别的元素和属性具有相同名称时,scalaxb 失败
【发布时间】:2018-08-26 10:22:09
【问题描述】:

我正在尝试使用 sbt-scalaxbFixRepository.xsd 生成绑定,但它不喜欢 SUBJ。

作为最后的手段,我可​​以稍微更改架构,但有没有办法调整 sbt-scalaxb 以理解原始文件?

sbt-scalaxb 不喜欢的 XSD 片段是:

xml <xs:element name="component"> <xs:complexType> <xs:sequence> <xs:element ref="messageEntity" minOccurs="0" maxOccurs="unbounded"/> </xs:sequence> <xs:attributeGroup ref="entityAttribGrp"/> <xs:attribute name="id" type="id_t" use="required"/> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="type" type="ComponentType_t" use="required"/> <xs:attribute name="repeating" type="BOOL_t" use="optional"/> <xs:attribute name="category" type="xs:string" use="optional"/> <xs:attribute name="abbrName" type="xs:string" use="optional"/> <xs:attribute name="notReqXML" type="BOOL_t" use="optional"/> <!-- would like to force a description of the component --> </xs:complexType> </xs:element>

【问题讨论】:

    标签: scala sbt xml-binding scalaxb sbt-scalaxb


    【解决方案1】:

    自己想通​​了:scalaxbAttributePrefix 设置为属性属性添加了前缀。

    build.sbt

    scalaxbAttributePrefix in (Compile, scalaxb) := Some("attr")
    

    生成的 FixRepository.scala

    case class Fix(
        ...,
        components: ...fixrepo.Components,
        ...,
        attributes: Map[String, scalaxb.DataRecord[Any]] = Map()
    ) {
        ...
        lazy val attrComponents = attributes("@components").as[BOOL_t]
        ...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多