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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T15:40:23+00:00 2026-05-15T15:40:23+00:00

I am using XOM to build XML documents in Java. I have created a

  • 0

I am using XOM to build XML documents in Java.

I have created a simple XML document, and I want an XML namespace. But when I set the namespace on the first tag, an empty namespace is set on the childs like xmlns="", how can I get rid of this behaviour? I only want xmlns on the first tag.

I want this XML:

<request xmlns="http://my-namespace">
    <type>Test</type>
    <data>
        <myData>test data</myData>
    </data>
</request>

But this is the XML document output from XOM

<request xmlns="http://my-namespace">
    <type xmlns="">Test</type>
    <data xmlns="">
        <myData>test data</myData>
    </data>
</request>

This is my Java XOM code:

String namespace = "http://my-namespace";
Element request = new Element("request", namespace);

Element type = new Element("type");
type.appendChild("Test");

request.appendChild(type);

Element data = new Element("data");
request.appendChild(data);

Element myData = new Element("myData");
myData.appendChild("test data");
data.appendChild(myData);

Document doc = new Document(request);
doc.toXML();
  • 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-15T15:40:23+00:00Added an answer on May 15, 2026 at 3:40 pm

    This works for me. However, I’m a bit puzzled as to why the Element objects don’t inherit the namespace of their parents, though. (Not an XML nor XOM expert)

    Code:

    String namespace = "http://my-namespace";
    Element request = new Element("request", namespace);
    
    Element type = new Element("type", namespace);
    type.appendChild("Test");
    
    request.appendChild(type);
    
    Element data = new Element("data", namespace);
    request.appendChild(data);
    
    Element myData = new Element("myData", namespace);
    myData.appendChild("test data");
    data.appendChild(myData);
    
    Document doc = new Document(request);
    System.out.println(doc.toXML());
    

    Output:

    <?xml version="1.0"?>
    <request xmlns="http://my-namespace">
      <type>Test</type>
      <data>
        <myData>test data</myData>
      </data>
    </request>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 490k
  • Answers 490k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer First of all, it's a really bad idea to use… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer If you are not dead set on using a listbox,… May 16, 2026 at 9:17 am
  • Editorial Team
    Editorial Team added an answer killproc will terminate programs in the process list which match… May 16, 2026 at 9:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

TASK : I have an existing xml document (UTF-8) which uses xml namespaces and
Say I want to output a huge set of search results, as XML, into
I'm using Windows and have a batch file (contents attached below) where I'm building
I'm using XOM with the following sample data: Element root = cleanDoc.getRootElement(); //find all
Is it possible to convert nu.XOM.Element to org.w3c.dom.Element ? Am trying to construct XML
I am using the CURL c++ api to get quotes from Yahoo's financial API.
I need to read smallish (few MB at the most, UTF-8 encoded) XML files,
In my job project I have recently been asked to generate POM files via
I was wondering which is the best way to turn a string (e.g. a

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.