[C#]验证错误(XSD导入DTD) [英] [C#]Validation error (XSD importing DTD)

查看:101
本文介绍了[C#]验证错误(XSD导入DTD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在针对链接到它的架构验证XML文件时遇到问题。我用XMLSpy和Liquid XML打开了这个文件,两者都有问题验证它。错误似乎集中在XSD结构中的特定部分,其中XSD文件导入
DTD文件。此外,许多公司已经使用了这种XML结构,这就是我不相信这是语法错误的原因。





所以这个问题的元素如下(我将发布文件和链接):


XML测试文件:


< pre class ="prettyprint"><?xml version =" 1.0"编码= QUOT; UTF-8英寸;?>
< dic:eclass_dictionary xmlns:dic =" urn:eclass:xml-schema:dictionary:2.0"的xmlns:ontoml = QUOT;瓮:ISO:STD:ISO:是:13584:-32:ED-1:技术:XML的模式:ontoml"的xmlns:CMN = QUOT;瓮:eclass中:XML的模式:普通:2.0"的xmlns:HEA = QUOT;瓮:eclass中:XML的模式:标题:2.0"的xmlns:IDT = QUOT;瓮:ISO:STD:ISO:TS:29002:-5:ED-1:技术:XML的模式:标识符QUOT;的xmlns:猫= QUOT;瓮:ISO:STD:ISO:TS:29002:-10:ED-1:技术:XML的模式:目录"的xmlns:基本= QUOT;瓮:ISO:STD:ISO:TS:29002:-4:ED-1:技术:XML的模式:基本"的xmlns:VAL = QUOT;瓮:ISO:STD:ISO:TS:29002:-10:ED-1:技术:XML的模式:值"的xmlns:EXT = QUOT;瓮:X-ontoml的扩展:模式:芯"的xmlns:DT = QUOT;瓮:eclass中:模板:XML的模式:数据类型:2.0"的xmlns:的xsi = QUOT; HTTP://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation =" urn:eclass:xml-schema:dictionary:2.0 http://www.eclass.eu/static/eClassXML/2.0/eCl@ssXML/dictionary.xsd">
< ontoml:ontoml>
< dictionary>
< contained_classes>
< ontoml:class xsi:type =" ontoml:CATEGORIZATION_CLASS_Type" ID = QUOT; 0173-1#01-AEI956#002">
< date_of_original_definition> 2011-11-18Z< / date_of_original_definition>
< date_of_current_version> 2012-11-27Z< / date_of_current_version>
< date_of_current_revision> 2012-11-27Z< / date_of_current_revision>
< revision> 1< / revision>
< status> 66< / status>
< source_language country_code =" US" LANGUAGE_CODE = QUOT;恩" />
< preferred_name>
< label country_code =" DE" LANGUAGE_CODE = QUOT; DE">笔记本和LT; /标签>
< / preferred_name>
< definition>
< text country_code =" DE" language_code =" de"> kleiner tragbarer Personal Computer,derüblicherweiseklappbarausgeführtthet< / text>
< / definition>
< its_superclass class_ref =" 0173-1#01-ACL245#004" />
< hierarchical_position> 19010202< / hierarchical_position>
< keywords>
< label country_code =" DE" LANGUAGE_CODE = QUOT; DE">撒哈拉/超便携-笔记本和LT; /标签>
< label country_code =" DE" language_code =" de">迷你笔记本< / label>
< label country_code =" DE" LANGUAGE_CODE = QUOT; DE">笔记本电脑和LT; /标签>
< label country_code =" DE" LANGUAGE_CODE = QUOT; DE">亚笔记本< /标签>
< label country_code =" DE" language_code =" de"> Tragbarer PC< / label>
< label country_code =" DE" LANGUAGE_CODE = QUOT; DE">亚笔记本和LT; /标签>
< / keywords>
< / ontoml:class>
< / contained_classes>
< / dictionary>
< / ontoml:ontoml>
< / dic:eclass_dictionary>

XSD1

< xs:schema xmlns =" urn:iso :STD:ISO:是:13584:-32:ED-1:技术:XML的模式:ontoml"的xmlns:IDT = QUOT;瓮:ISO:STD:ISO:TS:29002:-5:ED-1:技术:XML的模式:标识符QUOT;的xmlns:XS = QUOT; HTTP://www.w3.org/2001/XMLSchema"的targetNamespace = QUOT;瓮:ISO:STD:ISO:是:13584:-32:ED-1:技术:XML的模式:ontoml"将elementFormDefault = QUOT;不合格" attributeFormDefault = QUOT;不合格"> 
< xs:import namespace =" urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier"的schemaLocation = QUOT; ./ ISO29002 / identifier.xsd" />
< xs:simpleType name =" APosterioriSemanticRelationId">
< xs:restriction base =" idt:IRDI_type">
< xs:pattern value ="([0-9] {4})\ - ([A-Z0-9:_ \。] {1,35})(\-( [A-Z0-9:_\] {1,35})((\- [019])(\ - ([A-Z0-9] {1,10})_([A- Z0-9] {0,10})_([0-9] {1,5}))))#CE\ - ([A-Z0-9:???。_\] {1, 71})#[0-9] {1,9}" />
< xs:pattern value ="([0-9] {4})\ - ([A-Z0-9:_ \。] {1,35})\ - ([[ A-Z0-9:_\] {1,35})\-\ - ([A-Z0-9] {1,10})_([A-Z0-9] {0,10 })_([0-9] {1,5})#CE\ - ([A-Z0-9:_\] {1,71})#[0-9] {1,9} " />
< xs:pattern value ="([0-9] {4})\ - ([A-Z0-9:_ \。] {1,35})\-\ -\ - ([A-Z0-9] {1,10})_([A-Z0-9] {0,10})_([0-9] {1,5})#CE\ - ([A-Z0-9_:\] {1,71})#[0-9] {1,9}" />
< / xs:restriction>
< / xs:simpleType>
...
< / xs:schema>

XSD2:

<?xml版本= QUOT; 1.0"编码= QUOT; UTF-8英寸;?> 

<!DOCTYPE xs:schema [
<!ENTITY%identifier.dtd SYSTEM" identifier.dtd">
%identifier.dtd;
]>
< xs:schema targetNamespace =" urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier"
xmlns:id =" urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier"
xmlns:xs =" http://www.w3.org/2001/XMLSchema"将elementFormDefault = QUOT;合格"
attributeFormDefault =" unqualified">
<! - IRDI - >
< xs:element name =" IRDI"类型= QUOT; ID:IRDI_type" />
< xs:element name =" IRDI_list"类型= QUOT; ID:IRDI_list_type" />
< xs:simpleType name =" IRDI_type">
< xs:restriction base =" xs:string">
< xs:pattern value ="& irdi1;" />
< xs:pattern value ="& irdi2;" />
< xs:pattern value ="& irdi3;" />
< / xs:restriction>
< / xs:simpleType>
<! - IRDI序列 - >
< xs:complexType name =" IRDI_sequence_type">
< xs:sequence>
< xs:element ref =" id:IRDI"的minOccurs = QUOT; 0" maxOccurs的= QUOT;无界" />
< / xs:sequence>
< / xs:complexType>
<! - IRDI清单 - >
< xs:simpleType name =" IRDI_list_type">
< xs:list itemType =" id:IRDI_type" />
< / xs:simpleType>
< / xs:schema>

这两个XML编辑器(XMLSpy和Liquid XML)似乎都有这个XSD的问题,特别是这个部分:

< xs:pattern value ="& irdi1;" /> 

where"& ; irdi1;",&NBSP;"&安培; irdi2;"和&NBSP;"&安培; irdi3;"在导入的DTD中描述。


DTD

<! - 数字:0-9  - > 
<!ENTITY digit" 0-9">
<! - 内部分隔符 - >
<!ENTITY res":_ \。">
<! - 字母数字字符 - >
<!ENTITY alnum" 0-9A-Z">
<! - 安全字符 - >
<!ENTITY safe"& alnum;& res;">
<! - 国际代码指示符(ICD) - >
<!ENTITY icd" [& digit;] {4}">
<! - 组织标识符(OI) - >
<!ENTITY oi" [& safe;] {1,35}">
<! - 组织部件标识符(OPI) - >
<!ENTITY opi" [& safe;] {1,35}">
<! - 组织部件标识符源(OPIS) - >
<!ENTITY opis" [& alnum;] {1,1}">
<! - 附加信息(AI) - >
<!ENTITY ai" [& safe;] {1,70}">
<! - 代码空间标识符(CSI) - >
<!ENTITY csi" [& alnum;] {2,2}">
<! - 商品代码(IC) - >
<!ENTITY ic" [& safe;] {1,131}">
<! - 注册机构标识符(RAI) - >
<!ENTITY rai1" icd; - & oi;( - & opi;( - & opis;( - & ai;)?)?)?">
<!ENTITY rai2" icd; - & oi;( - & opi;)? - & ai;">
<!ENTITY rai3"& icd; - & oi; ---& ai;">
<! - 数据标识符 - >
<!ENTITY di" csi; - & ic;">
<! - 版本标识符(VI) - >
<!ENTITY vi" [0-9] {1,10}">
<! - 国际注册数据标识符(IRDI) - >
<!ENTITY irdi1"& rai1;(#& di;#& vi;)?">
<!ENTITY irdi2"& rai2;(#& di;#& vi;)?">
<!ENTITY irdi3"& rai3;(#& di;#& vi;)?">

所以当我尝试像这样读取XML文件:

 XmlReaderSettings xmlReaderSettings = new XmlReaderSettings(); 
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.IgnoreComments = true;
xmlReaderSettings.IgnoreWhitespace = true;
xmlReaderSettings.IgnoreProcessingInstructions = true;
xmlReaderSettings.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.ProcessSchemaLocation;

XmlReader reader = XmlReader.Create(" test_file.xml",xmlReaderSettings);

while(reader.Read())
{}

我在XML文件的第二个元素上得到一个异常:

'urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier:IRDI_type'未声明,或者不是一个简单的类型

SourceUri" http://www.eclass.eu/static/eClassXML/2.0/ontoML/identifier.xsd" (XSD1的URL)

因此,当我的程序尝试读取XSD1时,它会遇到idd:IRDI_type,它在XSD2中描述,用于导入DTD。发生了一些错误(可能是因为没有导入DTD),因此XSD2没有得到处理,因此程序没有为idt定义
:IRDI_type。


如果我在Visual Studio 2010 Web浏览器中打开XSD2,则& irdi1,& irdi2和& irdi3将替换为DTD中定义的正则表达式。所以我假设语法没问题。那么为什么我会收到验证错误?


我可以做些什么来验证XML文件?









解决方案

Hello dasiggo,


对于这个问题,我试图让有经验的人帮助你。如果我们有任何结果,我们会告诉你。


问候。


Hi,

I have a problem validating a XML file against the schema that is linked to it. I opened that file with XMLSpy and Liquid XML, and both have Problems validating it. The errors seem to center around a specific part in the XSD structure, where a XSD file imports a DTD file. Also, this XML structure is already used by many companies, that's why I don't believe that this is a syntax error.


So the elements of this Problem are as follows (I will post the files and the links):

XML test file:

<?xml version="1.0" encoding="UTF-8"?>
<dic:eclass_dictionary xmlns:dic="urn:eclass:xml-schema:dictionary:2.0" xmlns:ontoml="urn:iso:std:iso:is:13584:-32:ed-1:tech:xml-schema:ontoml" xmlns:cmn="urn:eclass:xml-schema:common:2.0" xmlns:hea="urn:eclass:xml-schema:header:2.0" xmlns:idt="urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier" xmlns:cat="urn:iso:std:iso:ts:29002:-10:ed-1:tech:xml-schema:catalogue" xmlns:basic="urn:iso:std:iso:ts:29002:-4:ed-1:tech:xml-schema:basic" xmlns:val="urn:iso:std:iso:ts:29002:-10:ed-1:tech:xml-schema:value" xmlns:ext="urn:x-ontoml-extensions:schema:core" xmlns:dt="urn:eclass:template:xml-schema:data-type:2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:eclass:xml-schema:dictionary:2.0 http://www.eclass.eu/static/eClassXML/2.0/eCl@ssXML/dictionary.xsd">
	<ontoml:ontoml>
		<dictionary>
			<contained_classes>
				<ontoml:class xsi:type="ontoml:CATEGORIZATION_CLASS_Type" id="0173-1#01-AEI956#002">
					<date_of_original_definition>2011-11-18Z</date_of_original_definition>
					<date_of_current_version>2012-11-27Z</date_of_current_version>
					<date_of_current_revision>2012-11-27Z</date_of_current_revision>
					<revision>1</revision>
					<status>66</status>
					<source_language country_code="US" language_code="en"/>
					<preferred_name>
						<label country_code="DE" language_code="de">Notebook</label>
					</preferred_name>
					<definition>
						<text country_code="DE" language_code="de">kleiner tragbarer Personal Computer, der üblicherweise klappbar ausgeführt ist</text>
					</definition>
					<its_superclass class_ref="0173-1#01-ACL245#004"/>
					<hierarchical_position>19010202</hierarchical_position>
					<keywords>
						<label country_code="DE" language_code="de">Sub-/Ultra-Portable-Notebooks</label>
						<label country_code="DE" language_code="de">Mini Notebook</label>
						<label country_code="DE" language_code="de">Laptop</label>
						<label country_code="DE" language_code="de">Subnotebook</label>
						<label country_code="DE" language_code="de">Tragbarer PC</label>
						<label country_code="DE" language_code="de">Sub-Notebook</label>
					</keywords>
				</ontoml:class>
			</contained_classes>
		</dictionary>
	</ontoml:ontoml>
</dic:eclass_dictionary>

XSD1:

<xs:schema xmlns="urn:iso:std:iso:is:13584:-32:ed-1:tech:xml-schema:ontoml" xmlns:idt="urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:iso:std:iso:is:13584:-32:ed-1:tech:xml-schema:ontoml" elementFormDefault="unqualified" attributeFormDefault="unqualified">
<xs:import namespace="urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier" schemaLocation="./ISO29002/identifier.xsd"/>
<xs:simpleType name="APosterioriSemanticRelationId">
<xs:restriction base="idt:IRDI_type">
<xs:pattern value="([0-9]{4})\-([A-Z0-9:_\.]{1,35})(\-([A-Z0-9:_\.]{1,35})((\-[019])(\-([A-Z0-9]{1,10})_([A-Z0-9]{0,10})_([0-9]{1,5}))?)?)?#CE\-([A-Z0-9:_\.]{1,71})#[0-9]{1,9}"/>
<xs:pattern value="([0-9]{4})\-([A-Z0-9:_\.]{1,35})\-([A-Z0-9:_\.]{1,35})\-\-([A-Z0-9]{1,10})_([A-Z0-9]{0,10})_([0-9]{1,5})#CE\-([A-Z0-9:_\.]{1,71})#[0-9]{1,9}"/>
<xs:pattern value="([0-9]{4})\-([A-Z0-9:_\.]{1,35})\-\-\-([A-Z0-9]{1,10})_([A-Z0-9]{0,10})_([0-9]{1,5})#CE\-([A-Z0-9_:\.]{1,71})#[0-9]{1,9}"/>
</xs:restriction>
</xs:simpleType>
...
</xs:schema>

XSD2:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xs:schema [
 <!ENTITY % identifier.dtd SYSTEM "identifier.dtd">
 %identifier.dtd;
]>
<xs:schema targetNamespace="urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier"
xmlns:id="urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" 
attributeFormDefault="unqualified">
 <!-- IRDI -->
 <xs:element name="IRDI" type="id:IRDI_type"/>
 <xs:element name="IRDI_list" type="id:IRDI_list_type"/>
 <xs:simpleType name="IRDI_type">
  <xs:restriction base="xs:string">
   <xs:pattern value="&irdi1;"/>
   <xs:pattern value="&irdi2;"/>
   <xs:pattern value="&irdi3;"/>
  </xs:restriction>
 </xs:simpleType>
 <!-- IRDI sequence -->
 <xs:complexType name="IRDI_sequence_type">
  <xs:sequence>
   <xs:element ref="id:IRDI" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
 </xs:complexType>
 <!-- IRDI list-->
 <xs:simpleType name="IRDI_list_type">
  <xs:list itemType="id:IRDI_type"/>
 </xs:simpleType>
</xs:schema>

Both XML Editors (XMLSpy and Liquid XML) seem to have a problem with this XSD, specifically with this part:

<xs:pattern value="&irdi1;"/>

where "&irdi1;", "&irdi2;" and "&irdi3;" are described in the imported DTD.

DTD:

<!-- Digits: 0-9 -->
<!ENTITY digit "0-9">
<!-- Internal separator character -->
<!ENTITY res ":_\.">
<!-- Alphanumeric character -->
<!ENTITY alnum "0-9A-Z">
<!-- Safe character -->
<!ENTITY safe "&alnum;&res;">
<!-- International Code Designator (ICD) -->
<!ENTITY icd "[&digit;]{4}">
<!-- Organization Identifier (OI) -->
<!ENTITY oi "[&safe;]{1,35}">
<!-- Organization Part Identifier (OPI) -->
<!ENTITY opi "[&safe;]{1,35}">
<!-- Organization Part Identifier Source (OPIS) -->
<!ENTITY opis "[&alnum;]{1,1}">
<!-- Additional Information (AI)-->
<!ENTITY ai "[&safe;]{1,70}">
<!-- Code Space Identifier (CSI) -->
<!ENTITY csi "[&alnum;]{2,2}">
<!-- Item Code (IC) -->
<!ENTITY ic "[&safe;]{1,131}">
<!-- Registration Authority Identifier (RAI) -->
<!ENTITY rai1 "&icd;-&oi;(-&opi;(-&opis;(-&ai;)?)?)?">
<!ENTITY rai2 "&icd;-&oi;(-&opi;)?--&ai;">
<!ENTITY rai3 "&icd;-&oi;---&ai;">
<!-- Data Identifier  -->
<!ENTITY di "&csi;-&ic;">
<!-- Version Identifier (VI) -->
<!ENTITY vi "[0-9]{1,10}">
<!-- International Registration Data Identifier (IRDI) -->
<!ENTITY irdi1 "&rai1;(#&di;#&vi;)?">
<!ENTITY irdi2 "&rai2;(#&di;#&vi;)?">
<!ENTITY irdi3 "&rai3;(#&di;#&vi;)?">

So when I try to read the XML file like that:

XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.IgnoreComments = true;
xmlReaderSettings.IgnoreWhitespace = true;
xmlReaderSettings.IgnoreProcessingInstructions = true;
xmlReaderSettings.ValidationFlags = System.Xml.Schema.XmlSchemaValidationFlags.ProcessSchemaLocation;

XmlReader reader = XmlReader.Create("test_file.xml" ,xmlReaderSettings);

while (reader.Read()) 
{}

I get an exception on the second element of the XML file:

'urn:iso:std:iso:ts:29002:-5:ed-1:tech:xml-schema:identifier:IRDI_type' is not declared, or is not a simple type

SourceUri "http://www.eclass.eu/static/eClassXML/2.0/ontoML/identifier.xsd" (The URL for XSD1)

So when my program tries to read XSD1, it encounters the idt:IRDI_type which is described in XSD2 that imports the DTD. Some error happens (probably because the DTD didn't get imported), so that XSD2 doesn't get processed, therefore the program has no definition for idt:IRDI_type.

If I open XSD2 in Visual Studio 2010 Web Browser, &irdi1, &irdi2 and &irdi3 are replaced with regular expressions defined in the DTD. So I assume that the syntax is OK. Then why do I get a validation error?

Is there something I can do to get the XML file validated?




解决方案

Hello dasiggo,

For this issue, I am trying to involve someone who is experienced with it to help you. If we have any result, we will tell you.

Regards.


这篇关于[C#]验证错误(XSD导入DTD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆