启用片段级一致性时会忽略 XML 模式验证吗?
从我对 XML 和架构验证的观察来看,似乎当片段级一致性< /a> 已为 XMLReader 实例启用, XML 源停止根据任何包含的架构进行验证。
但是,我无法从 MSDN 文档中验证这一点,因为它似乎没有根据一致性级别描述 XSD 架构行为。另外,如果我认为这个问题是真的,我找不到解决方法。
我想知道如何根据 XSD 架构验证 XML片段。
在我的例子中,我正在根据 XHTML 1 严格架构。事实上,像
From my sojourn with XML and Schema validation, it seems that when fragment-level conformance is enabled for an XMLReader instance, the XML source stops being validated against any included Schemas.
However I cannot verify this from the MSDN documentation as it doesn't seem to describe XSD Schema behaviour in light of conformance level. Also if I assume this problem is true, I cannot find a workaround for it.
I would like to know how to validate a XML fragment against an XSD Schema.
In my case I'm validating against the XHTML 1 Strict Schema. By the fact deprecated HTML tags like <center> are not being flagged as invalid, this is part of the reason I believe fragment conformance ignores schema. Also when I use document-level conformance in the same scenario, validity errors are successfully flagged.
For a code sample of the type of validation scenario I'm using see this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我在这篇MSKB文章中找到了答案,标题很奇怪如何:验证Visual C#.NET 中针对 XML 架构的 XML 片段 文章底部指出:
我认为该段落中有一个错误,其目的是说明 XML 中的
顶级元素
schema
文档/片段
根据 XML 架构进行验证
因为 Microsoft 代码示例在顶层(而不是在文档中任意地)开始其片段,所以它可以进行验证。然而,就我而言,我采用的是中间文档结构。
如果我的解释有误,请纠正我。
解决方法/解决方案
解决方法是我将片段填充到顶级元素中以进行验证。
换句话说,如果我正在处理 XHTML 片段:
我可以将其包装以进行验证 符合 XHTML 严格架构:
此解决方案适合我,因此我将暂时使用它;我还不确定是否存在更好的解决方案。
I think I found the answer in this MSKB article oddly enough titled HOW TO: Validate XML Fragments Against an XML Schema in Visual C#.NET The bottom of the article states:
I believe there is a mistake in that paragraph and the intention is to state
top-level elements in the XML
schema
document/fragment
are validated against an XML Schema
Because the Microsoft code sample starts its fragment at the top level (instead of arbitrarily inside a document) it works with validation. However in my case I'm taking a mid-document construct.
Correct me if my interpretation is wrong.
Workaround/solution
A workaround is for me to stuff my fragments inside a top level element for the purpose of validation.
In other words if I'm dealing with the XHTML fragment:
I can wrap it for validation to conform to the XHTML Strict Schema as:
This solution works for me so I'll use it in the interim; whether or not a better solution exists I'm unsure yet.