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

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?

0
YZlat
Asked:
YZlat
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.
0
 
YZlatAuthor Commented:
Great!

Thanks a lot Carl!
0

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