You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-dev@xerces.apache.org by bu...@apache.org on 2001/03/13 23:00:01 UTC

[Bug 966] New - serialize xml with internal dtd generate not-well-formed xml

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=966

*** shadow/966	Tue Mar 13 14:00:01 2001
--- shadow/966.tmp.8108	Tue Mar 13 14:00:01 2001
***************
*** 0 ****
--- 1,82 ----
+ +============================================================================+
+ | serialize xml with internal dtd generate not-well-formed xml               |
+ +----------------------------------------------------------------------------+
+ |        Bug #: 966                         Product: Xerces-J                |
+ |       Status: NEW                         Version: 1.3.0                   |
+ |   Resolution:                            Platform: PC                      |
+ |     Severity: Normal                   OS/Version: Other                   |
+ |     Priority:                           Component: Serialization           |
+ +----------------------------------------------------------------------------+
+ |  Assigned To: xerces-j-dev@xml.apache.org                                  |
+ |  Reported By: czhao@commonvision.com                                       |
+ |      CC list: Cc:                                                          |
+ +----------------------------------------------------------------------------+
+ |          URL:                                                              |
+ +============================================================================+
+ |                              DESCRIPTION                                   |
+ When I serialize a DOM object with internal DTD, the output is no longer a well-
+ formed xml document.
+ 
+ For example, I simply construct a DOM ojbect from dummy.xml and then serialize 
+ it:
+ 
+ dummy.xml:
+ <?xml version="1.0"?>
+ <!DOCTYPE foo  [
+         <!ELEMENT foo (bar*)>
+         <!ELEMENT bar (#PCDATA)>
+ ]>
+ <foo>
+         <bar> blar... </bar>
+ </foo>
+ 
+ 
+ TestSerialize.java:
+ import javax.xml.parsers.*;
+ import org.w3c.dom.*;
+ import org.xml.sax.*;
+ import org.apache.xml.serialize.*;
+ 
+ 
+ public class TestSerialize {
+ 
+ 
+         public static void main(String[] argv) {
+                 try {
+                         System.setProperty
+ ("javax.xml.parsers.DocumentBuilderFactory",
+                                  "org.apache.xerces.jaxp.DocumentBuilderFactoryI
+ mpl");
+                         DocumentBuilderFactory dbf =  
+ DocumentBuilderFactory.newInstance();
+                         dbf.setValidating(true);
+                         DocumentBuilder db = dbf.newDocumentBuilder();
+                         Document doc = db.parse("file:///d:/dummy.xml");
+                         java.io.StringWriter sw = new java.io.StringWriter();
+                         XMLSerializer xmlSer = new XMLSerializer(sw, null);
+                         xmlSer.serialize(doc);
+                         System.out.println(sw.toString());
+                 } catch (Exception e) {
+                         e.printStackTrace();
+                 }
+         }
+ }
+ 
+ 
+ Output:
+ 
+ 
+         <!ELEMENT foo (bar*)>
+         <!ELEMENT bar (#PCDATA)>
+ <?xml version="1.0"?>
+ <foo>  <bar> blar... </bar> </foo>
+ 
+ 
+ This is not well-formed and I cannot hand it directly to the next piece of xml 
+ app.  I tried to use different methods in OutputFormat class and still gets the 
+ same output.  The only thing I can do is to call
+                         xmlSer.serialize(doc.getDocumentElement());
+ In which case I lose the DTD altogether.
+ 
+ Is the output format by design or is it a bug?  Is there any way to generate a 
+ well-formed xml with internal DTD through serialization?

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-dev-help@xml.apache.org