如何向 XSD 中的元素添加属性

发布于 2024-12-20 00:58:24 字数 867 浏览 1 评论 0原文

我正在使用 jibx 创建 xml。我的要求是获取如下 Xml

<report>
  <info>
   <meta name="acntNo">11111111</meta> 
   <meta name="location">USA</meta> 
   <meta name="Id">2222222222</meta> 
  </info>
</report>

我的问题是如何将 name 属性 添加到 complexElement 元。我将从 java 代码中获取名称属性和元文本的值。

我尝试使用

<xsd:complexType name="CareInfoType">
    <xsd:sequence>
        <!--  root of the meta -->
        <xsd:element name="meta" type="qdx:CareMetaInfo" minOccurs="1" maxOccurs="3">
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="CareMetaInfo">
    <xsd:attribute name="name" type="xsd:string" ></xsd:attribute>
</xsd:complexType>

提前感谢

I'm using jibx to create a xml. the requirement i have is to get Xml as below

<report>
  <info>
   <meta name="acntNo">11111111</meta> 
   <meta name="location">USA</meta> 
   <meta name="Id">2222222222</meta> 
  </info>
</report>

My Question is how to add name attribute to the complexElement meta. I'll get the values of name attribute and meta text from java code.

I tried using

<xsd:complexType name="CareInfoType">
    <xsd:sequence>
        <!--  root of the meta -->
        <xsd:element name="meta" type="qdx:CareMetaInfo" minOccurs="1" maxOccurs="3">
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="CareMetaInfo">
    <xsd:attribute name="name" type="xsd:string" ></xsd:attribute>
</xsd:complexType>

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤凫 2024-12-27 00:58:24

您应该使用 xsd:simpleContent 机制向可以包含简单类型值的元素添加属性。您可以在此处阅读教程。下面是另一个示例

架构

<xsd:complexType name="SizeType">
  <xsd:simpleContent>
    <xsd:extension base="xsd:integer">
      <xsd:attribute name="system" type="xsd:token"/>
    </xsd:extension>
  </xsd:simpleContent>
</xsd:complexType>

示例

<size system="US-DRESS">10</size>

You should use xsd:simpleContent mechanism to add an attribute to an element that can contain values of simple types. You can read the tutorial here. Below is another example

Schema

<xsd:complexType name="SizeType">
  <xsd:simpleContent>
    <xsd:extension base="xsd:integer">
      <xsd:attribute name="system" type="xsd:token"/>
    </xsd:extension>
  </xsd:simpleContent>
</xsd:complexType>

Example

<size system="US-DRESS">10</size>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文