引用XML schema,怎么不报错啊

dsfse232 2012-05-10 09:48:48
下面是一段XML schema文档
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3school.com"
xmlns="http://www.w3school.com"
elementFormDefault="qualified">
<xsd:element name ="Book" type ="xsd:string"></xsd:element>
</xsd:schema>
此XML schema文档只声明了一个Book元素,保存为XMLSchema1.xsd文件

下面是引用上面schema文档的XML文档
<?xml version="1.0" encoding="utf-8"?>
<Boo xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com XMLSchema1.xsd"> //引用XMLSchema1.xsd文件
刘德华
</Boo>
这段XML能在浏览器中正确显示


我的问题:
schema文档中不是声明了一个Book元素吗,XML文档是引用schema文档的,而XML文档中的元素是Boo,为什么不报错呢?还能在浏览器中正确显示。
...全文
291 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
rrrrr32 2012-05-11
  • 打赏
  • 举报
回复
还是等牛人来吧.........
test2050 2012-05-11
  • 打赏
  • 举报
回复
http://www.bianceng.cn/xml/x31.htm
可能引用schema文档并不是要严格按它来吧,希望牛人解释下。
dsfse232 2012-05-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 的回复:]
“xsi:schemaLocation="http://www.w3schools.com XMLSchema1.xsd”
可能引用失败了。
其实W3C上面的例子很好实践,不用这样引用,一般都是XmlReaderSettings方法验证。下面是完整的C#例子,已验证
http://www.cnblogs.com/chenxizhang/archive/2009/06/19/1507121.h……
[/Quote]
可是,实际引用的时候,就是这样用的啊,为什么会引用失败呢?总得要找到原因吧
  • 打赏
  • 举报
回复
“xsi:schemaLocation="http://www.w3schools.com XMLSchema1.xsd”
可能引用失败了。
其实W3C上面的例子很好实践,不用这样引用,一般都是XmlReaderSettings方法验证。下面是完整的C#例子,已验证
http://www.cnblogs.com/chenxizhang/archive/2009/06/19/1507121.html
dsfse232 2012-05-11
  • 打赏
  • 举报
回复
等待牛人...........
rrrrr32 2012-05-11
  • 打赏
  • 举报
回复
VS不能验证吗?
孟子E章 2012-05-11
  • 打赏
  • 举报
回复
国外也有人说,IE不能验证
http://w3schools.invisionzone.com/index.php?showtopic=34669
孟子E章 2012-05-11
  • 打赏
  • 举报
回复
浏览器不一定进行验证的,一般格式良好就可以显示的。你可可以应用程序看一下,就知道了

private void Form1_Load(object sender, EventArgs e)
{

XmlReaderSettings settings = new XmlReaderSettings();
settings.ValidationType = ValidationType.Schema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;
settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
settings.ValidationEventHandler += new ValidationEventHandler(ValidationCallBack);
XmlReader reader = XmlReader.Create(@"L:\mvc2\WindowsFormsApplication2\XMLFile1.xml", settings);
while (reader.Read()) ;

}
private static void ValidationCallBack(object sender, ValidationEventArgs args)
{
if (args.Severity == XmlSeverityType.Warning)
MessageBox.Show("警告:" + args.Message);
else
MessageBox.Show("错误:" + args.Message);

}
rrrrr32 2012-05-11
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 的回复:]
我在VS2010,VS2008里面测试报错 的,说Boo未定义的
[/Quote]
我的也是VS2010啊,没报错呢,右键XML文件,在浏览器中查看,结果能查看啊
孟子E章 2012-05-11
  • 打赏
  • 举报
回复
我在VS2010,VS2008里面测试报错 的,说Boo未定义的

孟子E章 2012-05-11
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="utf-8"?>
<Boo xmlns="http://www.w3school.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3school.com XMLSchema1.xsd">
刘德华
</Boo>
rrrrr32 2012-05-11
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]
w3schools你写错,应该是
w3school
[/Quote]
w3school还是不报错,我是问的为什么不报错,引用schema应该报错啊
孟子E章 2012-05-11
  • 打赏
  • 举报
回复
w3schools你写错,应该是
w3school
dsfse232 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]
你的 Boo 是根了。不是Element
[/Quote]
不管这么说,schema文档没有定义Boo元素,XML引用schema文档,就应该报错吧,为什么不报错呢?
机器人 2012-05-10
  • 打赏
  • 举报
回复
你的 Boo 是根了。不是Element

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧