我尝试针对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验证文件。
问候
Björn