假设我的 Web 服务发出 XML,其中“xmlns”、“xmlns:xsi”和“xsi:schemaLocation”设置为无效 URI 的占位符(例如“blahblahblah”),并且一旦该服务已从众多系统中使用的用户发现他的 XML 解析器不喜欢占位符。
现在我必须对它做点什么。选项之一是仅删除“xmlns”、“xmlns:xsi”和“xsi:schemaLocation”属性。
删除它们可能会破坏现有用户吗?这样的 XML 是否有效?
假设我的 Web 服务发出 XML,其中“xmlns”、“xmlns:xsi”和“xsi:schemaLocation”设置为无效 URI 的占位符(例如“blahblahblah”),并且一旦该服务已从众多系统中使用的用户发现他的 XML 解析器不喜欢占位符。
现在我必须对它做点什么。选项之一是仅删除“xmlns”、“xmlns:xsi”和“xsi:schemaLocation”属性。
删除它们可能会破坏现有用户吗?这样的 XML 是否有效?
If you previously had a xmlns
attribute in your document element, it means that all XML elements (with no prefix) were in a namespace. If you now remove that namespace, this is no true anymore and the output of any (namespace-aware) parser changes. And with that, most probably the behavior of the programs working on the parsed data.
Just as an example, using XPath in Java is different if the XML elements are in a namespace: How to query XML using namespaces in Java with XPath?. Although the accepted answer shows a way to use XPath in a namespace-agnostic way, most programs will probably not use this approach.
The XML should still be valid (actually well-formed), you can easily check that in a decent XML editor that supports validation (including Eclipse for example). But because you removed the reference to the Schema, validation will only cover basic XML rules (as I said, the well-formedness), not the rules set up by the Schema.
So in short, yes, you may break your clients but yes, the XML would (probably) still be valid.
如果 XML 文件以前格式正确,那么它们仍然是格式正确的。有效性并不真正适用,因为您没有指向具有 xsi:location 属性的正确模式文档。
事实上,抱怨的用户可能是唯一一个试图验证您的文件的人。您的其他消费者在占位符方面做得很好。除非他们有专门定制的软件来“识别”你的 blahblahblah 发明,否则他们可能完全没有这些属性规范。