Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

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?

ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

Great!

Thanks a lot Carl!