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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:21:02+00:00 2026-06-08T23:21:02+00:00

I am trying to add a default namespace to a root element that is

  • 0

I am trying to add a default namespace to a root element that is in a different namespace but XOM doesn’t like this!

e.g

<env:contentEnvelope 
xmlns:env="http://data.com/Envelope/2008-05-01/" 
xmlns:inv="http://Patents.data.com/2012-01-01/" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

I want the inv namespace to also be the default namespace by adding
e.g.

xmlns="http://Patents.data.com/2012-01-01/"

but XOM won’t have it!

Any ideas on how to do this?

  • 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-06-08T23:21:04+00:00Added an answer on June 8, 2026 at 11:21 pm

    It was a combination of things that stopped me from adding a default namespace.
    The solution as with most things in IT is straight forward but not easy getting there:

    The key here is using the .addNamespaceDeclaration(“”, namespace) with the first param set to “” this is not intuitive I was using .setNamespace() which doesn’t work.

    Also I didn’t realise that creating an element using:

    new Element("env:CEnvelope", IConstants.ENV_NAMESPACE);
    

    automatically creates a namespace xmlns:env in the root element; I was explicitly doing this again; this doesn’t cause an issue but if you use .addNamespaceDeclaration(“”, namespace) after this it doesn’t work.

    The line with ** is all you need:

    private void setRoot(){
    
      Element root = new Element("env:CEnvelope", IConstants.ENV_NAMESPACE);    
    
      //Add root Element to the Document
      this.doc = new Document(root);
    
      root.addNamespaceDeclaration("xsi", IConstants.XSI_NAMESPACE);
      **root.addNamespaceDeclaration("", IConstants.PAT_NAMESPACE);
      //root.setNamespaceURI(IConstants.PAT_NAMESPACE);
      //root.addNamespaceDeclaration("env", IConstants.ENV_NAMESPACE);
    

    Oh yes, I didn’t need the inv namespace as this is the same as the default namespace!

    Cheers 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to add <session-management> in my Spring Security namespace configuration so that I
I'm trying add data triggers to the default combobox style so each text item
I am trying to manipulate SharePoint's default calendar to add, edit and delete items
Im new to asp.net mvc. I'm trying add new model class but it got
Trying to add a blank sample app for a rails tutorial to GitHub, but
Trying to add a class object into a List using reflection, but when invoking
I'm trying to run the userOptions script for MediaWiki to add a new namespace
I have been trying to find the answer to this simple question - but
I'm trying to debug my c# application that check MIPS syntax. But its not
I am trying to add a row to my Model and have that option

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.