将命名空间添加到 MSXML 时出现问题(使用 setProperty('SelectionNamespaces', ...))
不久前,我提出了一个关于 MSXML 中命名空间的使用的问题。起初,我用 XPath *[local-name()]-hack 绕过了整个事情(请参阅我之前的帖子),但由于良心危机,我决定以正确的方式做事。 (噢!)
考虑以下 XML:
<?xml version="1.0" encoding="UTF-8"?>
<Root xsi:schemaLocation="http://www.foo.bar mySchema.xsd" xmlns="http://www.foo.bar" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyElement>
</MyElement>
</Root>
当我尝试使用 IXMLDOMDocument3.setProperty('SelectionNamespaces', NSString); 添加这些命名空间时,出现以下错误:
“SelectionNamespaces 属性值无效。仅格式正确的 xmlns 允许使用属性。”。
删除命名空间 xsi:schemaLocation="http://www.foo.bar mySchema.xsd"
时,一切都运行顺利。我在这里做错了什么?有没有XML 中的错误?
A while back, I asked a question regarding the usage of namespaces in MSXML. At first, I circumvented the whole thing with the XPath *[local-name()]
-hack (see my previous post), but having a crisis of conscience I decided to do things the right way. (Doh!)
Consider the following XML:
<?xml version="1.0" encoding="UTF-8"?>
<Root xsi:schemaLocation="http://www.foo.bar mySchema.xsd" xmlns="http://www.foo.bar" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MyElement>
</MyElement>
</Root>
When I try to add these namespaces using IXMLDOMDocument3.setProperty('SelectionNamespaces', NSString);
, I get the following error:
"SelectionNamespaces property value is invalid. Only well-formed xmlns
attributes are allowed.".
When removing the namespace xsi:schemaLocation="http://www.foo.bar mySchema.xsd"
, everything runs smoothly. What am I doing wrong here? Is there an error in the XML? Is MSXML to blame?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
xsi:schemaLocation="..."
不是命名空间定义,它是 xsi 命名空间中
元素的属性。因此,像您一样从命名空间列表中删除它已经是解决方案了。
xsi:schemaLocation="..."
is not a namespace definition, it is an attribute of the<Root>
element which is in xsi namespace.So removing this from the list of namespaces as you did is already the solution.