Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » XML binding: problems with DOCTYPE on saving XML
XML binding: problems with DOCTYPE on saving XML [message #405453] Tue, 21 November 2006 11:27 Go to next message
Eclipse User
Originally posted by: joerg.von.frantzius.artnology.com

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
there are two issues I currently have with the DOCTYPE header. In my
original XML that I load using EMF, the following is found at the
beginning (replaced URL to DTD with "someurl"):<br>
<blockquote>&lt;!DOCTYPE JobSheet PUBLIC "-//Springer-Verlag//DTD A++
V2.4//EN" <a class="moz-txt-link-rfc2396E" href="http://someurl.dtd">"http://someurl.dtd"</a>&gt;<br>
</blockquote>
Now when I load and save that XML (with code as found in my previous
article with subject "NPE in
XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2272)"), the DTD
from the given URL is included completely as comments in the saved XML!
Is there any way of turning this off, or will I need to manually scrape
the comments from the DocumentRoot object?<br>
<br>
Secondly, I didn't get EMF to write the DOCTYPE header at all. I tried
the following:<br>
<blockquote>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Map saveOptions = new HashMap();</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; saveOptions.put(XMLResource.OPTION_SAVE_DOCTYPE, Boolean.TRUE);</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>((XMLResource)resource).setDoctypeInfo</b>("-//Springer-Verlag//DTD A++ V2.4//EN", <a class="moz-txt-link-rfc2396E" href="http://someurl.dtd">"http://someurl.dtd"</a>);</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [..]
</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Document document = ((XMLResource)resource).save(null,saveOptions,null);
</pre>
</blockquote>
<br>
But that doesn't write any DOCTYPE header. When looking at the code,
this is because XMLSaveImpl.toDom is true. But when I try the
alternative save method<br>
<blockquote>
<blockquote>
<pre>FileOutputStream fos = ...;
((XMLResource)resource).save(fos, saveOptions);
</pre>
</blockquote>
</blockquote>
that results in XMLSaveImpl.toDom==false, all I get is the following
NPE:<br>
<blockquote><tt>Exception in thread "main"
java.lang.NullPointerException<br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.StringSegment.write(StringSeg ment.java:394) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.write(XMLSaveImpl .java:875) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:227) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:203) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993) <br>
&nbsp;&nbsp;&nbsp; at TestSerialization.main(TestSerialization.java:72)</tt><br>
</blockquote>
Is there anything I'm doing wrong here?<br>
<br>
Thanks for any hints,<br>
J&ouml;rg<br>
</body>
</html>
Re: XML binding: problems with DOCTYPE on saving XML [message #405454 is a reply to message #405453] Tue, 21 November 2006 12:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26152
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050101050706070009060306
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

J
Re: XML binding: problems with DOCTYPE on saving XML [message #405455 is a reply to message #405453] Tue, 21 November 2006 12:03 Go to previous message
Eclipse User
Originally posted by: joerg.von.frantzius.artnology.com

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
OK everything's perfect now, neither of the problems occurs when I
create a new XMLResource:<br>
<br>
<tt> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; Map saveOptions = new HashMap();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; saveOptions.put(XMLResource.OPTION_SCHEMA_LOCATION,
Boolean.FALSE);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; saveOptions.put(XMLResource.OPTION_SAVE_DOCTYPE, Boolean.TRUE);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ExtendedMetaData emd = new BasicExtendedMetaData() {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public String getNamespace(EPackage ePackage) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (ePackage == AplusplusPackage.eINSTANCE) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return null;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return super.getNamespace(ePackage);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; @Override<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; public EPackage getPackage(String namespace) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (namespace==null) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return AplusplusPackage.eINSTANCE;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return super.getPackage(namespace);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; };<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; saveOptions.put(XMLResource.OPTION_EXTENDED_META_DATA, emd);<br>
<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AplusplusResourceFactoryImpl appResFactory = new
AplusplusResourceFactoryImpl();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; XMLResource xmlResource = (XMLResource)
appResFactory.createResource(URI.createFileURI("output.xml")); <br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xmlResource.setDoctypeInfo("-//Springer-Verlag//DTD A++
V2.4//EN",&nbsp; <a class="moz-txt-link-rfc2396E" href="http://someurl.dtd">"http://someurl.dtd"</a>);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xmlResource.setEncoding("UTF-8");<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; xmlResource.getContents().add(jobSheet);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; AplusplusXMLProcessor appXMLProc = new AplusplusXMLProcessor();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; try {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; appXMLProc.save(fos, xmlResource, saveOptions);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; } catch (IOException e) {<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; // TODO Auto-generated catch block<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; e.printStackTrace();<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }</tt><br>
<br>
J&ouml;rg von Frantzius wrote:
<blockquote cite="midejunpt$vh$1@utils.eclipse.org" type="cite">
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
Hi,<br>
<br>
there are two issues I currently have with the DOCTYPE header. In my
original XML that I load using EMF, the following is found at the
beginning (replaced URL to DTD with "someurl"):<br>
<blockquote>&lt;!DOCTYPE JobSheet PUBLIC "-//Springer-Verlag//DTD A++
V2.4//EN" <a class="moz-txt-link-rfc2396E" href="http://someurl.dtd">"http://someurl.dtd"</a>&gt;<br>
</blockquote>
Now when I load and save that XML (with code as found in my previous
article with subject "NPE in
XMLSaveImpl.saveElementFeatureMap(XMLSaveImpl.java:2272)"), the DTD
from the given URL is included completely as comments in the saved XML!
Is there any way of turning this off, or will I need to manually scrape
the comments from the DocumentRoot object?<br>
<br>
Secondly, I didn't get EMF to write the DOCTYPE header at all. I tried
the following:<br>
<blockquote>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Map saveOptions = new HashMap();</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; saveOptions.put(XMLResource.OPTION_SAVE_DOCTYPE, Boolean.TRUE);</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <b>((XMLResource)resource).setDoctypeInfo</b>("-//Springer-Verlag//DTD A++ V2.4//EN", <a
class="moz-txt-link-rfc2396E" href="http://someurl.dtd">"http://someurl.dtd"</a>);</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; [..]
</pre>
<pre>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Document document = ((XMLResource)resource).save(null,saveOptions,null);
</pre>
</blockquote>
<br>
But that doesn't write any DOCTYPE header. When looking at the code,
this is because XMLSaveImpl.toDom is true. But when I try the
alternative save method<br>
<blockquote>
<blockquote>
<pre>FileOutputStream fos = ...;
((XMLResource)resource).save(fos, saveOptions);
</pre>
</blockquote>
</blockquote>
that results in XMLSaveImpl.toDom==false, all I get is the following
NPE:<br>
<blockquote><tt>Exception in thread "main"
java.lang.NullPointerException<br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.StringSegment.write(StringSeg ment.java:394) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.write(XMLSaveImpl .java:875) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.XMLSaveImpl.save(XMLSaveImpl. java:227) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doSave(XMLRes ourceImpl.java:203) <br>
&nbsp;&nbsp;&nbsp; at
org.eclipse.emf.ecore.resource.impl.ResourceImpl.save(Resour ceImpl.java:993) <br>
&nbsp;&nbsp;&nbsp; at TestSerialization.main(TestSerialization.java:72)</tt><br>
</blockquote>
Is there anything I'm doing wrong here?<br>
<br>
Thanks for any hints,<br>
J&ouml;rg<br>
</blockquote>
<br>
</body>
</html>
Previous Topic:XML binding: how to save XML without namespace prefixes?
Next Topic:Programmatic code generation from an ecore model
Goto Forum:
  


Current Time: Fri Oct 31 20:56:54 GMT 2014

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

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