XML使用XSD验证 [英] XML Validated using XSD
问题描述
当我使用XSD验证XML时出现以下错误。我不知道代码中有什么问题。
无法找到属性的架构信息
无法找到元素的架构信息
无法找到元素的架构信息
无法找到元素的架构信息
无法找到元素的架构信息
我的C#代码
< pre lang =c#> XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add( null ,xsdFilePath);
settings.Schemas.Add( null ,xsdFilePath1);
settings.Schemas.Add( null ,xsdFilePath2);
settings.Schemas.Add( null ,xsdFilePath3);
settings.ValidationFlags | = XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags | = XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.ValidationFlags | = XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler + = new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create(xmlFilePath,settings);
while (reader.Read());
我的XML
< root >
< firstchild >
< first name = >
< ; br mode < span class =code-keyword> = hold / 跨度> >
< last name = > < / last >
< br mode = hold / >
< 地址 > < / address >
< / first >
< < span class =code-leadattribute> / firstchild >
< second child = >
< 报告 >
< tin > < / tin >
< name > < 名称 >
< / name > < / name >
< / report >
< / second > br mode =hold/>
< / root >
我的XSD
< xsd:schema xmlns:ftc = urn:oecd:ties:fatca:v1 xmlns:xsd = http://www.w3.org/2001/XMLSchema xmlns:sfa = urn:oecd:ties:stffatcatypes:v1 xmlns:iso = 瓮:OECD:关系:isofatcatypes:V1\" targetnamespace = urn:oecd:ties:fatca:v1 elementformdefault = 合格 attributeformdefault = 不合格 version = 1.1 >
< xsd:import namespace = urn:oecd:ties:isofatcatypes:v1 schemalocation = < span class =code-keyword> isofatcatypes_v1.0.xsd / >
< xsd:导入 命名空间 = urn:oecd:ties:stffatcatypes:v1 schemalocation = stffatcatypes_v1.1.xsd / > < / xsd:schema >
你的代码没有任何问题(首先看看)。你的xml文件有问题。
请阅读:使用命名空间在XML Schema中 [ ^ ]。它可能有助于您解决问题。
when I am validating the XML with XSD I got the following errors.I dont know what wrong in my code.
Could not find schema information for the attribute
Could not find schema information for the element
Could not find schema information for the element
Could not find schema information for the element
Could not find schema information for the element
my C# code
XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.Schemas.Add(null, xsdFilePath);
settings.Schemas.Add(null, xsdFilePath1);
settings.Schemas.Add(null, xsdFilePath2);
settings.Schemas.Add(null, xsdFilePath3);
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create(xmlFilePath, settings);
while (reader.Read()) ;
My XML
<root>
<firstchild>
<first name="">
<br mode="hold" />
<last name=""> </last>
<br mode="hold" />
<address> </address>
</first>
</firstchild>
<second child="">
<report>
<tin> </tin>
<name> <name>
</name></name>
</report>
</second>br mode="hold" />
</root>
My XSD
<xsd:schema xmlns:ftc="urn:oecd:ties:fatca:v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:sfa="urn:oecd:ties:stffatcatypes:v1" xmlns:iso="urn:oecd:ties:isofatcatypes:v1" targetnamespace="urn:oecd:ties:fatca:v1" elementformdefault="qualified" attributeformdefault="unqualified" version="1.1">
<xsd:import namespace="urn:oecd:ties:isofatcatypes:v1" schemalocation="isofatcatypes_v1.0.xsd" />
<xsd:import namespace="urn:oecd:ties:stffatcatypes:v1" schemalocation="stffatcatypes_v1.1.xsd" /></xsd:schema>
There's nothing wrong in your code (o the first look). There is something wrong in your xml file.
Please, read this: Working with Namespaces in XML Schema[^]. It might help you to resolve your issue.
这篇关于XML使用XSD验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!