Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XML Namespace not being propagated(XML namespaces not being propagated through child elements after converstion)
icon5.gif  XML Namespace not being propagated [message #1758440] Tue, 28 March 2017 17:00 Go to next message
Andrew McCaffrey is currently offline Andrew McCaffreyFriend
Messages: 3
Registered: March 2017
Junior Member
Hi,

I have an instance of an EMF model which I manipulate to get into the form I need. However, when I convert that model into an XMLResource, the default namespace is only being placed into the root element. An example of what comes out:

<fhir:Bundle xmlns:fhir="hXXp://hl7.org/fhir">
<id value="ecb8c8d9-1f9b-4bcf-a4f2-63be1a96a7ec"/>
<type value="searchset"/>
<entry id="7848e252-c5fd-486d-9756-f63a17ae3219">
...
</fhir:Bundle>

All of the elements should be living in the "hXXp://hl7.org/fhir" namespace (that's how it exists in the original schema), but only the top element is. Is there something I am doing wrong in the conversion that stops the namespace from being propagated to the child elements?

(I had to break the links as it wouldn't let me post the message with the links properly written out.)

Thanks for your time,
-Andrew McCaffrey
Re: XML Namespace not being propagated [message #1758477 is a reply to message #1758440] Wed, 29 March 2017 06:36 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29453
Registered: July 2009
Senior Member
Are you using a model generated from an XML Schema? When creating the resource to save your instance are you using the resource factory generated for your model?
Re: XML Namespace not being propagated [message #1758537 is a reply to message #1758477] Wed, 29 March 2017 17:23 Go to previous messageGo to next message
Andrew McCaffrey is currently offline Andrew McCaffreyFriend
Messages: 3
Registered: March 2017
Junior Member
Hi,

Yes, the model was generated from schema.

I am using the Factory to create the main resource and its children.

I have noticed that this behavior seems to happen if I create a non-root element and then append a child to it. The first thing I create has the namespace correctly, but nothing descending from it does. Is it possible I am creating the child incorrectly and/or assigning the link incorrectly? For example here's a "Parameters" element and I am attempting to make a "ParametersParameter" element as a child of it:

Parameters params = FhirFactory.eINSTANCE.createParameters();
ParametersParameter param = FhirFactory.eINSTANCE.createParametersParameter();
params.getParameter().add(param);

"Parameters" has the correct namespace, but "ParametersParameter" has no namespace.

Thanks,
-Andrew
Re: XML Namespace not being propagated [message #1758569 is a reply to message #1758537] Thu, 30 March 2017 08:07 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 29453
Registered: July 2009
Senior Member
I generated the model and the test project for https://www.hl7.org/fhir/fhir-all.xsd and used the FhirExample.java to test your assertions. I changed the example like this:
        Resource resource = resourceSet.createResource(URI.createURI("http:///My.fhir"));
        DocumentRoot documentRoot = FhirFactory.eINSTANCE.createDocumentRoot();
        
        Parameters params = FhirFactory.eINSTANCE.createParameters();
        ParametersParameter param = FhirFactory.eINSTANCE.createParametersParameter();
        params.getParameter().add(param);
        documentRoot.setParameters(params);
        
        resource.getContents().add(documentRoot);
        resource.save(System.out, null);
and running it produces this:
<?xml version="1.0" encoding="ASCII"?>
<fhir:Parameters xmlns:fhir="http://hl7.org/fhir">
  <fhir:parameter/>
</fhir:Parameters>
If I comment out all the options in the generated resource factory:
  public Resource createResource(URI uri)
  {
    XMLResource result = new FhirResourceImpl(uri);
//    result.getDefaultSaveOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
//    result.getDefaultLoadOptions().put(XMLResource.OPTION_EXTENDED_META_DATA, Boolean.TRUE);
//
//    result.getDefaultSaveOptions().put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE);
//
//    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
//    result.getDefaultSaveOptions().put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE);
//
//    result.getDefaultLoadOptions().put(XMLResource.OPTION_USE_LEXICAL_HANDLER, Boolean.TRUE);
    return result;
  }
it products this
<?xml version="1.0" encoding="ASCII"?>
<fhir:DocumentRoot xmlns:fhir="http://hl7.org/fhir">
  <parameters>
    <parameter/>
  </parameters>
</fhir:DocumentRoot>
If I now change the example to this:
        Resource resource = resourceSet.createResource(URI.createURI("http:///My.fhir"));
        
        Parameters params = FhirFactory.eINSTANCE.createParameters();
        ParametersParameter param = FhirFactory.eINSTANCE.createParametersParameter();
        params.getParameter().add(param);
        
        resource.getContents().add(params);
        resource.save(System.out, null);
then it produces:
<?xml version="1.0" encoding="ASCII"?>
<fhir:Parameters xmlns:fhir="http://hl7.org/fhir">
  <parameter/>
</fhir:Parameters>
That's what you are apparently seeing, so I think you're not using the generated resource factory to create the resource that you're using to produce the serialization you're showing.
Re: XML Namespace not being propagated [message #1759202 is a reply to message #1758569] Fri, 07 April 2017 15:52 Go to previous message
Andrew McCaffrey is currently offline Andrew McCaffreyFriend
Messages: 3
Registered: March 2017
Junior Member
Ah, thanks for the information! I'll go back and look to see how these objects are being created.

Thanks!
-Andrew
Previous Topic:is there a way to ignore an EPackage during the java code generation ?
Next Topic:How to do JAXB annotations in ecore?
Goto Forum:
  


Current Time: Wed Jul 18 18:13:56 GMT 2018

Powered by FUDForum. Page generated in 0.01570 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top