XmlDocument and VB.NET

Posted on 2006-03-21
Last Modified: 2008-03-03
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="" xsi:noNamespaceSchemaLocation="../XSD/schema1.xsd".


here is my code to accomplish that:
''add attributes to the root node
root.SetAttribute("xmlns:xsi", "")
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="" xsi:noNamespaceSchemaLocation="../XSD/schema1.xsd".


I get

<root xmlns:xsi="" noNamespaceSchemaLocation="../XSD/schema1.xsd".


Why is it happening and how can I fix it?

Question by:YZlat
    LVL 52

    Accepted Solution

    Changing the second line to:

       root.SetAttribute("noNamespaceSchemaLocation", "", "../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.
    LVL 35

    Author Comment


    Thanks a lot Carl!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now