Search code examples
namespacesmsxml

Problem adding namespaces to MSXML (using setProperty('SelectionNamespaces', ...))


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?


Solution

  • 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.