既属性和子元素XSD元素 [英] XSD element with both attributes and child elements

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

问题描述

我想知道的定义含有属性和子元素(如果可能)一个元素正确的语法。例如:

I want to know the correct syntax for defining an element containing both attributes and child elements (if possible). For example:

<component type="A" binding="B">
  <operation name="X">
    <input type="C" />
  </operation>

  <event name="Y">
    <output type="D" />
  </event>
</component>

正如你所看到的,这两种元素组成,操作和事件都具有的属性和子元素。是否有可能在XSD定义呢?怎么样?

As you can see, both elements component, operation and event have both attributes and child element. Is it possible to define this in XSD? How?

非常感谢你!

推荐答案

这是一种可能的方式来定义一个XSD符合XML;学习XSD的时候,你可以报名参加该推断XSD你,从一个或多个XML文件样本启动工具的帮助。

This is one possible way to define an XSD matching your XML; when learning XSD, you could enroll the help of a tool that infers the XSD for you, starting from one or more XML sample files.

<?xml version="1.0" encoding="utf-8"?>
<!--W3C Schema generated by QTAssistant/W3C Schema Refactoring Module (http://www.paschidev.com)-->
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:element name="component">
    <xsd:complexType>
      <xsd:sequence>
        <xsd:element name="operation">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="input">
                <xsd:complexType>
                  <xsd:attribute name="type" type="xsd:string" use="required" />
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
            <xsd:attribute name="name" type="xsd:string" use="required" />
          </xsd:complexType>
        </xsd:element>
        <xsd:element name="event">
          <xsd:complexType>
            <xsd:sequence>
              <xsd:element name="output">
                <xsd:complexType>
                  <xsd:attribute name="type" type="xsd:string" use="required" />
                </xsd:complexType>
              </xsd:element>
            </xsd:sequence>
            <xsd:attribute name="name" type="xsd:string" use="required" />
          </xsd:complexType>
        </xsd:element>
      </xsd:sequence>
      <xsd:attribute name="type" type="xsd:string" use="required" />
      <xsd:attribute name="binding" type="xsd:string" use="required" />
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

如您演练这一点,你可能会开始调整分钟/ maxOccurs的,使用(必填/可选),重用定义等生成的XSD是一个很好的起点,但通常最终被编辑过这样或那样的...

As you walkthrough this, you may start tweaking min/maxOccurs, use (required/optional), reusing definitions, etc. A generated XSD is a good starting point, but typically ends up being edited one way or another...

这篇关于既属性和子元素XSD元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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