Move the NameSpace declaration to Inner element [message #1821935] |
Sun, 23 February 2020 18:59 |
Palraj Jayaraj Messages: 15 Registered: June 2015 |
Junior Member |
|
|
Hello,
I'm using the IBM RQM's webservice for creating Test cases from my application. While sending the data to the server, it follows feed.xsd and qm.xsd. We have created the ECORE model from these XSDs and we have populated various model data from the application. Now, I have to serialize the EMF model to an XML file before sending across to the web service server. I have attached the schemas along with this post.
When I save the EMF model, I see that all the namespaces are saved to the root element (that is feed element)
<?xml version="1.0" encoding="ASCII"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:qm="http://jazz.net/xmlns/alm/qm/v0.1/">
<entry>
<content type="application/xml">
<qm:testcase>
<dc:title>testTitle</dc:title>
<qm:category term="category" value="QM"/>
</qm:testcase>
</content>
</entry>
</feed>
But, the web server accepts the below format only:
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<qm:testcase xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:qm="http://jazz.net/xmlns/alm/qm/v0.1/">
<dc:title>testTitle</dc:title>
<qm:category term="category" value="QM"/>
</qm:testcase>
</content>
</entry>
</feed>
When I send the first mentioned XML, it throws the below exception:
The uploaded content does not consist of well-formed XML or does not match the XML schema for testcase</ns2:message><ns2:trace>javax.xml.bind.UnmarshalException
- with linked exception:
[org.xml.sax.SAXParseException: The prefix "qm" for element "qm:testcase" is not bound.]
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:350)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:593)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:267)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:232)
Below is the code I use for serializing:
Resource xmlResource = new AtomResourceFactoryImpl().createResource(URI.createFileURI(new File("C:/temp/export/testCase.xml").getAbsolutePath()));
xmlResource.getContents().add(atomFeedDocumentModel);
Map<Object, Object> options = new HashMap<>();
xmlResource.save(options);
There is another ResourceFactory named QMResourceFactory. is there a way to generated the XML in such a way that the namespace is defined in the child element?
Attached the ECORE model overview as picture.
Please shed some light over this issue.
Thanks in advance,
Paul
-
Attachment: feed.xsd
(Size: 4.66KB, Downloaded 81 times) -
Attachment: qm.xsd
(Size: 550.77KB, Downloaded 83 times) -
Attachment: EMF overview.png
(Size: 22.04KB, Downloaded 66 times)
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02817 seconds