如何向 XSD 中的元素添加属性
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用 xsd:simpleContent 机制向可以包含简单类型值的元素添加属性。您可以在此处阅读教程。下面是另一个示例
架构
示例
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
Example