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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:22:08+00:00 2026-05-26T17:22:08+00:00

I’m going to simplify my classes and output as best I can here, but

  • 0

I’m going to simplify my classes and output as best I can here, but basically what I’m after is I want to add an org.w3c.dom.Element (representing an atom link in this case) to a JAXB object I’m returning. The JAXB Class looks something like:

import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlType;
import org.w3c.dom.Element;

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "People", namespace = "main", propOrder = {
    "any",
    "persons"
})
public class People {
    @XmlAnyElement
    protected List<Element> any;
    @XmlElement(name = "person", namespace = "main")
    protected List<Person> persons;
    [...]
}

I’m creating the Element using a template I create like this:

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import org.w3c.dom.DOMException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

public class ElementGen {
    public Element getTemplate() throws DOMException, SAXException, ParserConfigurationException {
        final SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        final Schema schema = sf.newSchema(new StreamSource(
                Thread.currentThread().getContextClassLoader().getResourceAsStream(ATOM_XSD)));
        final DocumentBuilderFactory docBuilder = DocumentBuilderFactory.newInstance();
        docBuilder.setSchema(schema);
        final Document doc = docBuilder.newDocumentBuilder().newDocument();
        linkTemplate = doc.createElementNS(ATOM_NAMESPACE, ATOM_LINK);
        return linkTemplate;
    }
}

(That’s not actually what the class looks like, I’m just trying to make it as easy as possible to compile something to test it without all the external mess).

I then clone that template using linkTemplate.cloneNode(false);

Now this all works in that it returns xml, but the odd thing is that the xml I get back has additional namespaces attached:

<atom:link xmlns:ns3="main" xmlns="" href="href" rel="rel"/>

If I add linkTemplate.setAttribute("xmlns", null); the “xmlns:ns3” namespace disappears and I get:

<atom:link xmlns="" href="href" rel="rel"/>

But there seems to be no way of removing that xmlns=””. Am I creating the Element in the wrong way? Or perhaps something else is going wrong? I’m rather at a loss as to why it’s adding these at all so any help/explanation would be appreciated.

Edit: I believe it must be related to the namespace of the document I use for generating the Element, but I’m not sure how to fix it. Is there any way of setting the (XML) targetNamespace on the document?

Edit 2: I’m not sure if it adds anything useful for anyone, but with more experimenting I found that linkTemplate.setAttribute("xmlns:" + anything, null); has the effect of creating a link with xmlns:[anything]="" and removing any others that would have otherwise been generated.

Edit 3: The relevant bits of the xsd used to generate the JAXB objects is:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0"
    xmlns="main"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:atom="http://www.w3.org/2005/Atom"
    targetNamespace="main"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">

<xs:complexType name="People">
    <xs:sequence>
        <xs:any namespace="##other" processContents="skip" minOccurs="0" maxOccurs="unbounded"/>
        <xs:element name="person" type="Person" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    [attributes]
</xs:complexType>
[other types etc.]
  • 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-26T17:22:09+00:00Added an answer on May 26, 2026 at 5:22 pm

    Since none of the suggestions here have worked for me I’ve decided to go a different route. In the end I ended up overwriting the Listener RESTEasy adds to the Marshaller with a Listener of my own. This Listener then calls the RESTEasy listener (if it was present), before adding the links manually on the RESTServiceDiscovery field (you have to get this field using reflection, and turn off access checking with field.setAccessible(true) before getting the object).

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

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported

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.