首页 > 解决方案 > 在 XSD 中使用冒号验证 XML 元素

问题描述

我尝试针对 XSD 架构验证以下 XML。

<feed xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="mynamespace">
	<id>MySet</id>
	<title type="text">MySet</title>
	<updated>2018-05-14T08:26:35Z</updated>
	<author>
		<name/>
	</author>
	<link href="LIST" rel="self" title="LIST"/>
	<entry>
		<id></id>
		<title type="text">MySet(value1='12345',Value2='001')</title>
		<updated>2018-05-14T08:26:35Z</updated>
		<category term="name.myset" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
		<link href="MySet(value1='12345',Value2='001')" rel="self" title=""MySet"/>
		<content type="application/xml">
			<m:properties xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices">
				<d:value1></d:value1>
				<d:value2></d:value2>
			</m:properties>
		</content>
	</entry>
	<link rel="delta" href="MySet?!deltatoken='0050568558461ED895EA10645A3EFAB7_20180514082634'"/>
</feed>

XSD 架构:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:m="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.w3.org/2005/Atom" 
version="1.0" elementFormDefault="qualified" 
xml:base="Mynamespace">
	<xsd:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>
	<xsd:element name="feed">
		<xsd:complexType>
			<xsd:sequence>
				<xsd:element name="id"/>
				<xsd:element name="title"/>
				<xsd:element name="updated"/>
				<xsd:element name="author"/>
				<xsd:element name="link"/>
				<xsd:element name="entry" maxOccurs="unbounded">
					<xsd:complexType>
						<xsd:sequence>
							<xsd:element name="id"/>
							<xsd:element name="title"/>
							<xsd:element name="updated"/>
							<xsd:element name="category"/>
							<xsd:element name="link"/>
							<xsd:element name="content">
								<xsd:complexType>
									<xsd:sequence>
										<xsd:element name="m:properties" maxOccurs="unbounded">
											<xsd:complexType>
												<xsd:sequence>
													<xsd:element name="Value1" minOccurs="0">
														<xsd:annotation>
															<xsd:documentation>Value1</xsd:documentation>
														</xsd:annotation>
														<xsd:simpleType>
															<xsd:restriction base="xsd:string">
																<xsd:maxLength value="12"/>
															</xsd:restriction>
														</xsd:simpleType>
													</xsd:element>
													<xsd:element name="Value2" minOccurs="0">
														<xsd:annotation>
															<xsd:documentation>Value2</xsd:documentation>
														</xsd:annotation>
														<xsd:simpleType>
															<xsd:restriction base="xsd:string">
																<xsd:maxLength value="12"/>
															</xsd:restriction>
														</xsd:simpleType>
													</xsd:element>
												</xsd:sequence>
											</xsd:complexType>
										</xsd:element>
									</xsd:sequence>
									<xsd:attribute name="type" type="xsd:string"/>
								</xsd:complexType>
							</xsd:element>
						</xsd:sequence>
					</xsd:complexType>
				</xsd:element>
			</xsd:sequence>
			<xsd:attribute ref="xml:base"/>
		</xsd:complexType>
	</xsd:element>
</xsd:schema>                                                                                  

问题是:我有名为“m:properties”和“d:value1”的元素。但这不是 xsd 中的有效 NCName。所以我的 xsd 验证失败。

有人知道如何用冒号验证名称吗?我无法更改 XML 内容。我只能更改 xsd 验证文件。

问候

比约恩

标签: xmlvalidationxsd

解决方案


推荐阅读