我不明白如何定义复杂类型。
今天我有这个:
<xsd:element name="batch_requests_callbacks">
<xsd:complexType>
<xsd:sequence>
<xsd:element ref="document_id" minOccurs="1" maxOccurs="1"/>
<xsd:choice minOccurs="0" maxOccurs="1">
<xsd:element ref="filename"/>
<xsd:element ref="error"/>
</xsd:choice>
<xsd:element ref="author" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="version" default="1.0"/>
</xsd:complexType>
</xsd:element>
Run Code Online (Sandbox Code Playgroud)
但是,然后,标签在标签中的顺序xsd:sequence很重要,我不希望这种行为。
如果我使用的xsd:all是没有标签顺序的标签,但是无法设置maxOccurs为无限制的标签,则无法在标签xsd:choice内部使用xsd:all
我有什么选择?
使用XML Schema声明a complexType只有一个子元素时,以下三种方法都实现了目标:
<xs:complexType> <xs:sequence> <xs:element ref="somevalue"/> </xs:sequence> </xs:comlexType>
<xs:complexType> <xs:choice> <xs:element ref="somevalue"/> </xs:choice> </xs:comlexType>
<xs:complexType> <xs:all> <xs:element ref="somevalue"/> </xs:all> </xs:comlexType>
Run Code Online (Sandbox Code Playgroud)
显然,sequence,choice和all不是必须的,为单独的元件,因为它们应当由用于指示多个元素的顺序.是否有一种更简洁的方式来声明complexType只有一个子元素?(即一个消除使用sequence,all或者choice,某种方式.)
我想做的是,声明一个名为“data”的父元素,它有 6 个子元素,这两个元素是有条件的,这意味着如果选择元素 A,则 B 不会出现在“data”中。
像这样:
<data>
<A>text1</A>
<B>text1</B>
<C>text1</C>
<D>text1</D>
<E>text1</E> or <F>text1</F>
</data>
Run Code Online (Sandbox Code Playgroud)
要求1:所有元素可以以任意顺序、任意次数出现。
要求2:元素E和F是有条件的,意味着只有其中之一出现在数据中。
我的xsd代码是这样的:
<xs:element name="data">
<xs:complexType>
<xs:sequence>
<xs:element name="sequence" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:choice minOccurs="0" maxOccurs="unbounded" >
<xs:element ref="A" />
<xs:element ref="B" />
<xs:element ref="C" />
<xs:element ref="D" />
<xs:choice>
<xs:element ref="E" />
<xs:element ref="F" />
<xs:element ref="G" />
</xs:choice>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="status"/>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
我已经尝试了所有这些链接,但仍然没有得到我的解决方案。
在XSD中,<complextType>可以具有'block'和'final'属性,它们可以取值#all或扩展或限制列表.这些属性意味着什么?我们如何使用它们?
我无法从W3C对XSD 1.1的建议中得到明确的答案.有人可以给我一些例子吗?
我寻找一种方法来检查我的 xsd,某个标签仅包含不同允许的字符串之一。
例如,两个允许的字符串是:
好的:
<TYPE>Index</TYPE>
<TYPE>Condition</TYPE>
Run Code Online (Sandbox Code Playgroud)
错误的:
<TYPE>Integer</TYPE>
Run Code Online (Sandbox Code Playgroud)
我的xsd中的type定义如下:
<xs:element name="TYPE">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
Run Code Online (Sandbox Code Playgroud) 我从 xsd 验证中得到了一些精神分裂的行为。此链接显示了 xml 和 xsd + 在线模式验证器中的错误。当我使用 xmllint 在本地运行此命令时
xmllint --noout --nonet --schema devhelp2.xsd tester.devhelp2
Run Code Online (Sandbox Code Playgroud)
我收到类似的警告:
tester.devhelp2:5: element sub: Schemas validity error : Element '{urn:devhelp}sub', attribute 'name': The attribute 'name' is not allowed.
tester.devhelp2:5: element sub: Schemas validity error : Element '{urn:devhelp}sub', attribute 'link': The attribute 'link' is not allowed.
tester.devhelp2:5: element sub: Schemas validity error : Element '{urn:devhelp}sub': The attribute '{urn:devhelp}name' is required but missing.
tester.devhelp2:5: element sub: Schemas validity error : Element '{urn:devhelp}sub': The attribute …Run Code Online (Sandbox Code Playgroud) 我试图在XSD文件上运行Xsd.exe,但出现以下错误。我正在使用IMPORT,因为主机命名空间与外部命名空间不同。
A2.xsd取决于A21.xsd,而后者又取决于A22.xsd(所有文件都位于同一文件夹中)
ERROR: "The datatype 'http://service.a1.com/base1/2005/:EmployeeDefinition' is missing"
xsd.exe /classes /out:C:\Temp\ "C:\Temp\A2.xsd" /language:CS
Run Code Online (Sandbox Code Playgroud)
A2.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.a1.com/base/2005/" xmlns:c1="http://service.a1.com/base1/2005/" elementFormDefault="qualified">
<xs:import namespace="http://service.a1.com/base1/2005/" schemaLocation="a21.xsd"/>
<xs:element name="Employee" nillable="true" type="c1:EmployeeDefinition" />
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
A21,XSD
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.a1.com/base1/2005/" xmlns:n2="http://service.a1.com/base2/2005/" elementFormDefault="qualified">
<xs:import namespace="http://service.a1.com/base2/2005/" schemaLocation="a22.xsd"/>
<xs:complexType name="EmployeeDefinition">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="EmployeeID" type="xs:int" />
<xs:element minOccurs="0" maxOccurs="1" name="FirstName" type="xs:string" />
<xs:element name="Address" nillable="true" type="n2:AddressDefinition" />
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
A22.xsd
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.a1.com/base2/2005/" elementFormDefault="qualified">
<xs:complexType name="AddressDefinition">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" …Run Code Online (Sandbox Code Playgroud) 我需要以友好的方式向用户显示XML文件,因此我创建了一个类似于树的结构,例如:http://thecodeplayer.com/walkthrough/css3-family-tree,而不是向用户显示原始XML.
现在,在创建新节点时,我正在验证服务器端.如果服务器验证了新建议的XML(树),那么我继续创建一个新节点.
无论如何,现在我想让用户拖动这些节点.当我在服务器端验证提议时拖动节点时,它将变慢.所以我的问题是如何根据客户端的模式验证XML文件,以便在拖动节点时我可以允许拖动节点,具体取决于验证是否成功.
I need a required attribute or element only if a specific value of an enumeration is chosen. 下面的例子:
<xs:element name="TYPE" type="TestEnum" />
<!-- // This Element should only required when TYPE = INTERNATIONAL -->
<xs:element name="IBAN"/>
</xs:complexType>
<xs:simpleType name="TestEnum">
<xs:restriction base="xs:string">
<xs:enumeration value="NATIONAL"/>
<xs:enumeration value="INTERNATIONAL"/>
</xs:restriction>
</xs:simpleType>
Run Code Online (Sandbox Code Playgroud)
我想编写一个简单的XML文件,其中包含位于我计算机上同一本地目录中的自定义xsd文件.我不明白文件开头的必要语法(我已经google了,但XSD教程似乎只关注元素定义而不是xsd:schema).
我的sys_params.xsd开始了:
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<xsd:element name="shipOrder" type="order"/>
Run Code Online (Sandbox Code Playgroud)
我的sys_params.xml开始了:
<shiporder orderid="889923"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com sys_params.xsd"
<orderperson>John Smith</orderperson>
Run Code Online (Sandbox Code Playgroud)
我的XML在xml上报告此验证错误:
错误架构文档"sys_params.xsd"具有与实例文档" http://www.w3schools.com "中指定的目标命名空间不同的目标命名空间
毫无疑问,我的代码是错误的,但我需要一些帮助来纠正它.