使用xml:id属性时出现XmlSchemaValidationException [英] XmlSchemaValidationException when using xml:id attribute

查看:209
本文介绍了使用xml:id属性时出现XmlSchemaValidationException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML文件,它使用此处定义的xml:id特殊属性:
http://www.w3.org/TR/xml-id/
- 但是,当我尝试解析此XML时,我得到以下异常:

I have an XML file that uses the xml:id special attribute as defined here: http://www.w3.org/TR/xml-id/ -- however, when I try to parse this XML I get the following exception:

The 'http://www.w3.org/XML/1998/namespace:id' attribute is not declared.

Exception: System.Xml.Schema.XmlSchemaValidationException
   Message: The 'http://www.w3.org/XML/1998/namespace:id' attribute is not declared.
     Stack:    at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(XmlSchemaValidationException e, XmlSeverityType severity)
    at System.Xml.Schema.XmlSchemaValidator.SendValidationEvent(String code, String arg)
    at System.Xml.Schema.XmlSchemaValidator.ValidateAttribute(String lName, String ns, XmlValueGetter attributeValueGetter, String attributeStringValue, XmlSchemaInfo schemaInfo)
    at System.Xml.XsdValidatingReader.ValidateAttributes()
    at System.Xml.XsdValidatingReader.ProcessElementEvent()
    at System.Xml.XsdValidatingReader.Read()
    at WindwardArrow.net.windward.arrow.datasource.xml.l.CanConnect()


<有人能告诉我为什么会这样吗?以下是XML的相关部分:

Can anyone tell me why this is happening? Here's the relevant section of the XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<data
    xmlns="urn:x-KP:psp:merge"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<recipient xml:id="IM00011_171761_1" include="cover_zh enclosureA_zh enclosureB_zh cover_en enclosureA_en enclosureB_en">
		...
	</recipient>
</data>

Malcolm McCrimmon

Malcolm McCrimmon

推荐答案

基本上你需要提供架构( http://www.w3.org/2004/10/xml.xsd )定义该属性,或者您可以尝试使用AllowXmlAttributes标志进行验证
$启用b $ b http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidationflags.aspx 可以解决问题。我不确定该标志是否支持xml:id属性,它可能只支持xml:lang和xml:base和xml:space。
Basically you need to supply a schema (http://www.w3.org/2004/10/xml.xsd) defining that attribute or you can try whether validating with the AllowXmlAttributes flag http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidationflags.aspx being enabled fixes the problem. I am not sure however that flag supports the xml:id attribute, it might only support xml:lang and xml:base and xml:space.


这篇关于使用xml:id属性时出现XmlSchemaValidationException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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