如何在 XSD 中定义一个简单的元素和属性 [英] How to define a simple element and attribute in XSD

查看:19
本文介绍了如何在 XSD 中定义一个简单的元素和属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 XML 如下所示:

My XML looks like this:

<test attri="value">content</test>

我无法在 XML Schema 中构建它,因为我无法提供 complexType 内容,也无法为 simpleType 提供属性.我觉得应该有一个非常简单的解决方案,但我忽略了这一点.

I have trouble building this in XML Schema, since I can't give a complexType content and can't give a simpleType an attribute. I feel like there should be a very simple solution to this that I am overlooking.

推荐答案

使用以下内容:

 <xs:element name="test ">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="attri" type="xs:string"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>

这篇关于如何在 XSD 中定义一个简单的元素和属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆