We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

XmlDocument and VB.NET

YZlat
YZlat asked
on
Medium Priority
675 Views
Last Modified: 2008-03-03
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?

Comment
Watch Question

Senior Systems and Integration Developer
CERTIFIED EXPERT
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
CERTIFIED EXPERT

Author

Commented:
Great!

Thanks a lot Carl!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.