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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:51:03+00:00 2026-06-17T07:51:03+00:00

I have a problem unmarshalling a rather simple XML-document to plain Java objects. This

  • 0

I have a problem unmarshalling a rather simple XML-document to plain Java objects.

This is what my XML looks like:

<?xml version="1.0" encoding="UTF-8"?>
<codeSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 vocab.xsd" xmlns="urn:hl7-org:v3">
     <name>RoleCode</name>
     <desc>Codes voor rollen</desc>
     <code code="SON" codeSystem="2.16.840.1.113883.5.111" displayName="natural sonSon ">
         <originalText>The player of the role is a male offspring of the scoping entity (parent).</originalText>
     </code>
     <code code="DAUC" codeSystem="2.16.840.1.113883.5.111" displayName="Daughter">
           <originalText> The player of the role is a female child (of any type) of scoping entity (parent) </originalText>
     </code>
</codeSystem>

It’s part of a much bigger file, a specification of the Hl7v3 code system for representing relationships between persons.

I created two Java classes for the CodeSystem and Code elements:

@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class CodeSystem
{
    private String name;

    private String desc;

    @XmlElement(name = "code")
    private List<Code> codes;
}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType
public class Code
{
    @XmlAttribute
    private String code;

    @XmlAttribute
    private String codeSystem;

    @XmlAttribute
    private String displayName;

    private String originalText;
}

I added a package-info.java containing:

@XmlSchema(
    namespace = "urn:hl7-org:v3",  
    elementFormDefault = XmlNsForm.UNQUALIFIED, 
    attributeFormDefault = XmlNsForm.UNQUALIFIED,
    xmlns = { 
        @javax.xml.bind.annotation.XmlNs(prefix = "", namespaceURI = "urn:hl7-org:v3") 
    }
)
package nl.topicuszorg.hl7v3.vocab2enum.model;

import javax.xml.bind.annotation.XmlNsForm;
import javax.xml.bind.annotation.XmlSchema;

Unmarshalling is pretty straightforward:

JAXBContext context = JAXBContext.newInstance(CodeSystem.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
CodeSystem codeSystem = (CodeSystem) unmarshaller.unmarshal(new File(args[0]));

This however results in an empty CodeSystem object. Nothing except the root element is parsed from the XML.

I can’t figure out why the name, desc and code elements aren’t recognized. Do they reside in a different namespace then the root element? They shouldn’t be, because the namespace declaration in the root element is unprefixed.

What am I missing?

  • 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-17T07:51:05+00:00Added an answer on June 17, 2026 at 7:51 am

    In your XML document you have specified a default namespace. This means that any non-prefixed element is going to be in that namespace. In the fragment below both the codeSystem and name elements are qualified with the urn:hl7-org:v3 namespace.

    <codeSystem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 vocab.xsd" xmlns="urn:hl7-org:v3">
         <name>RoleCode</name>
         ...
    </codeSystem>
    

    You just need to change the elementFormDefault property on the @XmlSchema annotation to XmlNsForm.QUALIFIED. You currently have it as XmlNsForm.UNQUALIFIED which means that only global elements will be namespace qualified (the one corresponding to @XmlRootElement in your use case.

    @XmlSchema(
        namespace = "urn:hl7-org:v3",  
        elementFormDefault = XmlNsForm.QUALIFIED, 
        attributeFormDefault = XmlNsForm.UNQUALIFIED,
        xmlns = { 
            @javax.xml.bind.annotation.XmlNs(prefix = "", namespaceURI = "urn:hl7-org:v3") 
        }
    )
    package nl.topicuszorg.hl7v3.vocab2enum.model;
    
    import javax.xml.bind.annotation.XmlNsForm;
    import javax.xml.bind.annotation.XmlSchema;
    

    For More Information

    • http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have problem to make work a resource file. This is my simple code
I have a problem using Jaxb2Marshaller for unmarshalling XML attributes (of primitive types). Here
I have a small XML document in the FIXML format. I'm unmarshalling them using
I have some problem when unmarshaling a .xml at a web service using JAXB.
I have problem with my query on C, I’m using the oci8 driver. This
Have problem while getting data from Memcached on .NET MVC solution. I have this
I have problem. I have this code, and I can`t add session. This is
I have problem with encoding data in Oracle database. I want to xor string
I'm working on a project using Java RMI. This is the class causing problem:

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.