• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 662
  • Last Modified:

XmlDocument and VB.NET

I have an XmlDocument with a root node



I want to add the following attributes to the root node:


so that my document look like this:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../XSD/schema1.xsd".


here is my code to accomplish that:
''add attributes to the root node
root.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance")
root.SetAttribute("xsi:noNamespaceSchemaLocation", "../XSD/schema1.xsd")

It works but for some reason in the second attribute it omits the "xsi:" prefix.

So instead of

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../XSD/schema1.xsd".


I get

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" noNamespaceSchemaLocation="../XSD/schema1.xsd".


Why is it happening and how can I fix it?

1 Solution
Carl TawnSystems and Integration DeveloperCommented:
Changing the second line to:

   root.SetAttribute("noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance", "../XSD/schema1.xsd")

Appears to work ok.

I guess the first one works ok because it is the namespace declaration. This second line specifies the namespace uri for the attribute so it automatically prefixes it with the correct identifier.

Hope this helps.
YZlatAuthor Commented:

Thanks a lot Carl!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now