XmlDocument and VB.NET

I have an XmlDocument with a root node

<root>

</root>

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

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

so that my document look like this:

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

</root>

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

</root>


I get

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

</root>

Why is it happening and how can I fix it?

LVL 35
YZlatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
YZlatAuthor Commented:
Great!

Thanks a lot Carl!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.