我想将元素中允许的位数限制为6:
<AccountNumber>123456</AccountNumber>
<AccountNumber>999999</AccountNumber>
<AccountNumber>000000</AccountNumber>
Run Code Online (Sandbox Code Playgroud)
字段格式规范是6位数,零填充,数字.
我看,我可能要使用的totalDigits限制,基于:
totalDigits指定允许的确切位数.必须大于零
所以我有简单的类型:
<xs:simpleType name="AccountNumber">
<xs:restriction base="xs:int">
<xs:totalDigits value="6"/>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
虽然它捕获无效数字,例如:
<AccountNumber>1234567</AccountNumber>
<AccountNumber>0000000</AccountNumber>
<AccountNumber></AccountNumber>
Run Code Online (Sandbox Code Playgroud)
它没有捕获无效的数字:
<AccountNumber>12345</AccountNumber>
<AccountNumber>01234</AccountNumber>
<AccountNumber>00123</AccountNumber>
<AccountNumber>00012</AccountNumber>
<AccountNumber>00001</AccountNumber>
<AccountNumber>00000</AccountNumber>
<AccountNumber>0000</AccountNumber>
<AccountNumber>000</AccountNumber>
<AccountNumber>00</AccountNumber>
<AccountNumber>0</AccountNumber>
Run Code Online (Sandbox Code Playgroud)
建议的限制是指定允许的确切位数?
假设我正在处理一个xsd:simpleType,它是一个字符串,需要具有特定的字符集和特定的最大长度,类似于下面的代码:
<xsd:simpleType name="MyType">
<xsd:restriction base="xsd:string">
<xsd:pattern value="[0-9]" />
<xsd:maxLength value="36" />
</xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)
所以我的xsd类型将是一个只有数字的字符串,最多36个字符.我的问题是xsd:pattern和xsd:maxLength(或任何其他类似的标签,如minLength)是否可以一起工作.我的直觉不是; 基于模式或基于长度的xsd元素仅在xsd:restriction中.因此,我必须将最大长度限制添加到模式中.
请注意,我通过在Java上解组xml并验证失败来测试它.无论如何,我正在寻找的信息是两个如何以及模式和maxLength可以一起工作的信息.
我的架构源如下所示:
<xsd:schema xmlns="uuid:b8fd4596-56ec-4718-ad00-bf2a70a148c2" xmlns:tcmi="http://www.tridion.com/ContentManager/5.0/Instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" targetNamespace="uuid:b8fd4596-56ec-4718-ad00-bf2a70a148c2">
<xsd:import namespace="http://www.tridion.com/ContentManager/5.0/Instance"></xsd:import>
<xsd:annotation>
<xsd:appinfo>
<tcm:Labels xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
<tcm:Label ElementName="description" Metadata="false">Description</tcm:Label>
<tcm:Label ElementName="multiline" Metadata="false">Multiline</tcm:Label>
</tcm:Labels>
</xsd:appinfo>
</xsd:annotation>
<xsd:element name="Blog">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="description" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:appinfo>
<tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0"></tcm:ExtensionXml>
</xsd:appinfo>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:normalizedString">
<xsd:minLength value="1"></xsd:minLength>
<xsd:maxLength value="20"></xsd:maxLength>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
<xsd:element name="multiline" minOccurs="0" maxOccurs="1" type="tcmi:MultiLineText">
<xsd:annotation>
<xsd:appinfo>
<tcm:ExtensionXml xmlns:tcm="http://www.tridion.com/ContentManager/5.0">
<configuration xmlns="http://www.sdltridion.com/2011/SiteEdit">
<field>
<editable>true</editable>
</field>
</configuration>
</tcm:ExtensionXml>
<tcm:Size xmlns:tcm="http://www.tridion.com/ContentManager/5.0">5</tcm:Size>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element></xsd:schema>
Run Code Online (Sandbox Code Playgroud)
我能够对"xsd:normalizedString"类型字段使用maxlength和minLength限制,但是我无法对"tcmi:MultiLineText"类型使用相同的限制.任何人都知道如何在这种类型的领域使用它们?
如果在该字段中无法使用该限制,我知道还有其他方法可以在Tridion中验证保存内容(正如Nuno和Robert在http://nunolinhares.blogspot.com.es/2012/07/validating中所解释的那样)-content-on-save-part-1-of.html和 …
以下是我在为SOAP服务生成客户端时尝试使用的xsd,Eclipse正在抛出错误:元素"xs:schema"的前缀"xs"未绑定.
<xs:schema version="1.0"
targetNamespace="bdo.com.ph/RemitAPI">
<xs:element name="CheckServiceResponse"
nillable="true" type="xs:string"/>
<xs:element name="apiRequest" nillable="true" type="tns:APIRequest"/>
.............................
<xs:element name="referenceNo" type="xs:string" form="qualified"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
我从webservice获得了这个xsd
如何保证url元素以"http://"开头?
<xs:element name="url" type="xs:anyURI"/>
Run Code Online (Sandbox Code Playgroud) 我有一个XSD验证我的XML文件.问题是它适用于一个元素,但是当我有多个元素时,它不起作用,我找不到问题.
这是我的XML文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<UrlList>
<url>
<url>https://www.youtube.com/watch?v=ke92CDVQsb8</url>
<idUrl>72</idUrl>
<urlShort>http://short.ly:8080/SOB/url/832261</urlShort>
<numVisits>2</numVisits>
</url>
<url>
<url>http://moodle.urv.cat/moodle/pluginfil</url>
<idUrl>73</idUrl>
<urlShort>http://short.ly:8080/SOB/url/45ea9b</urlShort>
<numVisits>1</numVisits>
</url>
</UrlList>
Run Code Online (Sandbox Code Playgroud)
这是我的XSD文件:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UrlList">
<xs:complexType>
<xs:sequence>
<xs:element ref="url"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="url">
<xs:complexType>
<xs:sequence>
<xs:element name="url" type="xs:string"/>
<xs:element name="idUrl" type="xs:integer"/>
<xs:element name="urlShort" type="xs:string"/>
<xs:element name="numVisits" type="xs:integer"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud) 我有这样的XML文件
<listOfA>
<a type="1">
<name></name>
<surname></surname>
</a>
<a type="2">
<name></name>
<id></id>
</a>
</listOfA>
Run Code Online (Sandbox Code Playgroud)
我想创建一个XSD,这样如果属性"type"的值为1,则必须存在name和surname元素,当它为2时,name和id必须在那里.我试图在XSD架构生成器中生成XSD ,但它使surname和id元素minOccurs = 0.我怎么能让它工作?
我找到了一些关于这个问题的提示,但仍然没有帮助我.
这是我的XML
<?xml version="1.0" encoding="UTF-8"?>
<work xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns="http://www.w3.org/2001/XMLSchema-instance"
tns:schemaLocation="myXSDSchema.xsd">
<tns:Objects>
<tns:Object Name=":" Location=":">
</tns:Object>
</tns:Objects>
</work>
Run Code Online (Sandbox Code Playgroud)
这是我的XSD文件:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:tns = "http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified">
(some checks)
</schema>
Run Code Online (Sandbox Code Playgroud)
我的XSD文件与XML位于同一文件夹中.
如何链接这2个文件?
我正在编写一个 XSD 来验证一个 XML,但是当我验证这个错误时出现了:
输出 - 错误
使用 XML 模式验证当前文件:
错误:元素“{ http://www.w3.org/2001/XMLSchema-instance }Gasto”:不需要此元素。预期是(加斯托)
......我不明白这个错误
这是我的 XML 示例:
<?xml version="1.0" encoding="UTF-8"?>
<Armazem>
<Lista_Gastos xmlns:artGasto="http://www.w3.org/2001/XMLSchema-instance"
artGasto:noNamespaceSchemaLocation="TraXSD.xsd">
<artGasto:Gasto id="50">
<artGasto:nome>Robalo</artGasto:nome>
<artGasto:quantidade>1</artGasto:quantidade>
</artGasto:Gasto>
</Lista_Gastos>
</Armazem>
Run Code Online (Sandbox Code Playgroud)
这是我的 XSD 示例:
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema elementFormDefault="qualified"
attributeFormDefault="unqualified"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:artGasto="http://www.w3.org/2001/XMLSchema-instance">
<xsd:element name="Armazem">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="Lista_Gastos"
type="TListGastos" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="TListGastos">
<xsd:sequence >
<xsd:element name="Gasto" type="TGasto"
maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TGasto">
<xsd:sequence >
<xsd:element name="nome" type="xsd:string" />
<xsd:element name="quantidade" type="xs:integer" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="required"/> …Run Code Online (Sandbox Code Playgroud) XML验证失败,错误:
元素'CategoryPageUrl':' http://www.example.com/products?my_query_parameter [] = 45'不是原子类型'xs:anyURI'的有效值.,第29行
Feed看起来像这样:
<Category>
<ExternalId>1234</ExternalId>
<Name>Name</Name>
<CategoryPageUrl>http://www.example.com/products?my_query_parameter[]=45</CategoryPageUrl>
</Category>
Run Code Online (Sandbox Code Playgroud)
适当的架构看起来像这样:
<xs:complexType name="CategoryType">
<xs:all>
<xs:element name="ExternalId" type="ExternalIdType" minOccurs="0"/>
<xs:element name="Name" type="xs:string" minOccurs="0"/>
<xs:element name="CategoryPageUrl" type="xs:anyURI" minOccurs="0"/>
</xs:all>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud) xsd-validation ×10
xsd ×8
xml ×6
java ×1
maxlength ×1
python ×1
regex ×1
simpletype ×1
tridion ×1
tridion-2011 ×1
validation ×1
xsd-1.1 ×1