简体   繁体   English

使用包含2个浮点数的元素序列定义XML模式

[英]Defining a XML Schema with a sequence of elements containing 2 floats

I'm trying to define a schema for XML-files like this: 我正在尝试为XML文件定义一个架构,如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<traverse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="test.xsd">
  <cp>1.0 2.0</cp>
  <cp>3.0 -2.0</cp>
  <cp>-1.365575 0</cp>
  <cp>4 1.3</cp>
</traverse>

It has to be a sequence of at least 3 cp's (control points) each defined by two doubles. 它必须是至少3个cp(控制点)的序列,每个序列由两个double定义。 I tried this (without the constraint that there have to be at least 3 control points): 我尝试了此操作(没有限制,必须至少有3个控制点):

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="traverse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="cp" type="control-point" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:simpleType name="listOfValues">
    <xs:list itemType="xs:double"/>
  </xs:simpleType>
  <xs:simpleType name="control-point">
    <xs:restriction base="listOfValues">
      <xs:length value="2"/>
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

When I try to validate the XML-file above, XMLSpy tells me that cp-tags arent't allowed inside the traverse-tag. 当我尝试验证上面的XML文件时,XMLSpy告诉我,遍历标签内不允许使用cp标签。 Can anyone help me? 谁能帮我? Thanks! 谢谢!

Change this: 更改此:

  <xs:sequence>
    <xs:element name="cp" type="control-point" />
  </xs:sequence>

to this: 对此:

  <xs:sequence>
    <xs:element name="cp" type="control-point" minOccurs="3" maxOccurs="unbounded"/>
  </xs:sequence>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM