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 115719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:03:51+00:00 2026-05-11T03:03:51+00:00

We were given a sample document, and need to be able to reproduce the

  • 0

We were given a sample document, and need to be able to reproduce the structure of the document exactly for a vendor. However, I’m a little lost with how C# handles namespaces. Here’s a sample of the document:

<?xml version='1.0' encoding='UTF-8'?> <Doc1 xmlns='http://www.sample.com/file' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'    xsi:schemaLocation='http://www.sample.com/file/long/path.xsd'>     <header>         <stuff>data</stuff>         <morestuff>data</morestuff>     </header>  </Doc1> 

How I’d usually go about this is to load a blank document, and then start populating it:

XmlDocument doc = new XmlDocument(); doc.LoadXml('<Doc1></Doc1>'); // Add nodes here with insert, etc... 

Once I get the document started, how do I get the namespace and schema into the Doc1 element? If I start with the namespace and schema in the Doc1 element by including them in the LoadXml(), then all of the child elements have the namespace on them — and that’s a no-no. The document is rejected.

So in other words, I have to produce it EXACTLY as shown. (And I’d rather not just write text-to-a-file in C# and hope it’s valid XML).

  • 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. 2026-05-11T03:03:52+00:00Added an answer on May 11, 2026 at 3:03 am

    You should try it that way

      XmlDocument doc = new XmlDocument();      XmlSchema schema = new XmlSchema();   schema.Namespaces.Add('xmlns', 'http://www.sample.com/file');    doc.Schemas.Add(schema); 

    Do not forget to include the following namespaces:

    using System.Xml.Schema; using System.Xml; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've had a look at the metronome sample given by Apple, however, the sample
Please see the sample xml given below. As per a requirement, I need to
Given a list of mailing addresses, I need to open an existing Word document,
Given the sample console application below: QUESTION #1 : Why does .Name() return typeof
Given this sample code: #include <iostream> #include <stdexcept> class my_exception_t : std::exception { public:
Given the sample code: class Base { public: bool pub; protected: bool prot; };
Given the following code sample: uint8_t i, in, ni; i = in = 2;
I am trying to sample a data frame from a given data frame such
Given a simple data set, I would like to be able to calculate a
Following on from my last question here OpenXML looks like it probably does exactly

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.