【问题标题】:mapping deeply nested element with namespaces while using happymapper使用happymapper时使用命名空间映射深度嵌套的元素
【发布时间】:2020-04-14 01:45:31
【问题描述】:

在 Ruby on Rails 6 环境中,我使用 happyMapper 来映射一些 xml 文件。

这是一个 XML 文件的片段

<Tag>
    <ClassName>Codice Fiscale</ClassName>
    <xs:xsd xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <xs:simpleType name="Codice Fiscale">
            <xs:restriction base="X4006E1450246">
                <xs:pattern value="\p{L}{6,6}[0-9LMNPQRSTUV][0-9LMNPQRSTUV]\p{L}[0-9LMNPQRSTUV][0-9LMNPQRSTUV]\p{L}[0-9LMNPQRSTUV][0-9LMNPQRSTUV][0-9LMNPQRSTUV]\p{L}"/>
                <xs:pattern value="\p{L}{6,6}\d\d\p{L}\d\d\p{L}\d\d\d\p{L}"/>
                <xs:pattern value="\d{11,11}"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:xsd>
    <Multiplicity>
        <MinOccurrence>1</MinOccurrence>
        <MaxOccurrence>1</MaxOccurrence>
    </Multiplicity>
</Tag>

一切正常,除了我无法正确解析 xs:xsd 元素:它总是返回 [""]

也许,部分复杂性在于我想将多个xs:pattern 子元素映射到一个has-many :patterns 元素中。

这是我的班级声明:

class Tag

    include HappyMapper

    #register_namespace 'nonamespace', ''
    register_namespace 'xs', 'http://www.w3.org/2001/XMLSchema'

    tag "Tag"

    element   :class_name, String, tag: 'ClassName'

    has_one   :min_occurrence, Integer, tag: 'Multiplicity/MinOccurrence'

    has_many  :patterns, String, tag: 'xs:xsd/xs:simpleType/xs:restriction/xs:pattern'

【问题讨论】:

    标签: xml mapping ruby-on-rails-6


    【解决方案1】:

    模式的正确定义是

    has_many  :patterns, String, tag: 'xsd/xs:simpleType/xs:restriction/xs:pattern/@value', namespace: 'xs'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-25
      • 1970-01-01
      • 1970-01-01
      • 2015-07-21
      • 1970-01-01
      • 1970-01-01
      • 2020-11-16
      相关资源
      最近更新 更多