将命名空间添加到 MSXML 时出现问题(使用 setProperty('SelectionNamespaces', ...))

发布于 2024-08-27 23:41:28 字数 832 浏览 5 评论 0原文

不久前,我提出了一个关于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2024-09-03 23:41:28

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文