Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 482559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T01:06:32+00:00 2026-05-13T01:06:32+00:00

I am creating XML out of Dataset by dataset.GetXML() method. I want to add

  • 0

I am creating XML out of Dataset by dataset.GetXML() method.
I want to add attributes to it

            XmlAttribute attr = xmlObj.CreateAttribute("xmlns:xsi");
            attr.Value = "http://www.createattribute.com";
            xmlObj.DocumentElement.Attributes.Append(attr);

            attr = xmlObj.CreateAttribute("xsi:schemaLocation");
            attr.Value = "http://www.createattribute.com/schema.xsd";
            xmlObj.DocumentElement.Attributes.Append(attr);

            xmlObj.DocumentElement.Attributes.Append(attr);

But when I open the XML file, I found “xsi:” was not there in the attribute for schemaLocation

           <root xmlns="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:xsi="http://www.createattribute.com"     
           schemaLocation="http://www.createattribute.com/schema.xsd">

I want the attribute like

           xsi:schemaLocation="http://www.createattribute.com/schema.xsd"

Is this always like this, or i m missing something here.
I am curious if anyone could help me if this could be resolved or give me some URL when I can find the solution for this

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T01:06:32+00:00Added an answer on May 13, 2026 at 1:06 am

    The key here is that you need to tell the XmlWriter what namespaces to use and from there it will apply the correct prefixes.

    In the code below the second parameter in the SetAttribute method is the namespace uri specified for xmlns:xsi namespace. This lets the XmlWrite put in the right prefix.

    XmlDocument xmlObj = new XmlDocument();
    xmlObj.LoadXml("<root></root>");
    
    XmlElement e = xmlObj.DocumentElement;
    e.SetAttribute("xmlns:xsi", "http://www.createattribute.com");
    e.SetAttribute("schemaLocation", "http://www.createattribute.com", "http://www.createattribute.com/schema.xsd");
    

    Similar code using the syntax from your original question is:

    XmlDocument xmlObj = new XmlDocument();
    xmlObj.LoadXml("<root></root>");
    
    XmlAttribute attr = xmlObj.CreateAttribute("xmlns:xsi");            
    attr.Value = "http://www.createattribute.com"; 
    xmlObj.DocumentElement.Attributes.Append(attr);
    
    attr = xmlObj.CreateAttribute("schemaLocation", "http://www.createattribute.com"); 
    attr.Value = "http://www.createattribute.com/schema.xsd"; 
    xmlObj.DocumentElement.Attributes.Append(attr); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying out TDD and creating fake objects, I want to use XML
I'm creating a new XML File out of a table. The problem is I
I am creating an xml schema as <?xml version=1.0 encoding=UTF-8?> <string xmlns=http://tempuri.org/> <Inventories> <ID>
I'm creating xml-like mark-up language using System.Xml.XmTextWriter that will be read by a third
I am creating an XML string using JQuery. I would like to open a
We are creating many XML files for a single app in developing android applications;
I am creating serialized XML for a LINQ to SQL project using the DataContractSerializer
I'm creating an XML file using Perl and XML::Simple module. I successfully create the
I'm creating an XML document. I got it to indent using TransformerFactory.setAttribute(indent-number, new Integer(2));
I am creating an XML document on the fly. and I need to know

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.