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

This is my main class code: public static void main(String[] args) { JFrame f=
Here is my code: public class Main { public static void main(String[] args) {
in the following code: public class ApplicationContext extends Application { private static ApplicationContext instance;
Error: Type mismatch: cannot convert from Set<ConstraintViolation<capture#1-of ?>> to Set<ConstraintViolation<Class<?>>> My code: public class
add-type -Language CSharpVersion3 -TypeDefinition @ public class pack_code { public pack_code() {} public string
Here is my code: public class Main extends Applet implements Runnable, KeyListener, java.awt.event.MouseListener {
I have a Tomcat application server and this Java source code: public class MyServlet
First, please look at this custom Button-inherited UserControl code: Public Class UserControl1 Dim _Text
I have this code to reveres the words in a sentence. using System; class
I have a class from which I want to get values from combo box

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.