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

  • Home
  • SEARCH
  • 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 4583592
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:14:11+00:00 2026-05-21T21:14:11+00:00

my class code as public class OpenShipments { private string _xmlns = ; private

  • 0

my class code as

public class OpenShipments
{
    private string _xmlns = "";
    private OpenShipment _OpenShipment = null;

    [XmlAttribute("xmlns")]
    public string xmlns
    {
        get { return _xmlns; }
        set { _xmlns = "x-schema:" + value; }
    }

    [XmlElement("OpenShipment")]
    public OpenShipment OpenShipment
    {
        get { return _OpenShipment; }
        set { _OpenShipment = value; }
    }

    public OpenShipments()
    {
        _OpenShipment = new OpenShipment();
    }
}

I include a property called public string xmlns which will have namespace after serializing the code, but no namespace is added when we see the xml.

In my case i need to add namespace dynamically to OpenShipments element whose value will be dynamically set. In my case namespace will look like xmlns="x-schema:C:\UPSLabel\OpenShipments.xdr" and sometime will look like xmlns="x-schema:d:\UPSLabel\OpenShipments.xdr".

So the namespace value x-schema:d:\UPSLabel\OpenShipments.xdr will differ based on condition. I need advice how to add namespace dynamically to handle the situation.

  • 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-21T21:14:11+00:00Added an answer on May 21, 2026 at 9:14 pm

    You can do it this way:

    when serialzing your class

            System.Xml.Serialization.XmlSerializer xs = new XmlSerializer(<my class>.GetType());
            XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
    
            if(<condition>)
            {
            ns.Add(string.Empty, @"x-schema:C:\UPSLabel\OpenShipments.xdr");
            } 
            else
            {
            ns.Add(string.Empty, @"x-schema:D:\UPSLabel\OpenShipments.xdr");
            }
    
            xs.Serialize(<stream>, <your class instance>,ns);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here is my example code: Public Class Parent Private _TestProperty As String Private WithEvents
Here is a VB.NET code snippet Public Class OOPDemo Private _strtString as String Public
I have the following (Java) code: public class TestBlah { private static final String
Consider the following code : public class RandomClass { private readonly string randomString; public
Given this code: public class Car { public virtual int CarId { get; set;
The following code public class GenericsTest2 { public static void main(String[] args) throws Exception
take a look at this example code: public class Comment { private Comment() {
Let's say I have some Java code: public class SomeClass { static { private
Let's assume we've got the following Java code: public class Maintainer { private Map<Enum,
This is my main class code: public static void main(String[] args) { JFrame f=

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.