DOM Document.cloneNode(true), in-memory validation, and Attr.getSpecified()

"Jacob Kjome" <[email protected]>
Newsgroups gmane.text.xml.xerces-j.user
Message-ID <[email protected]>
When I parse a document, with validation against a DTD, attributes that 
weren't explicitly specified in the parsed XML, but have default values in the 
DTD, correctly show up as "Attr.getSpecified() == false".  So far, so good.

However, after cloning the document (Document = (Document) 
doc.cloneNode(true)) all the equivalent cloned Attrs show up as 
"Attr.getSpecified() == true".  Is that to be expected or a bug?  And a 
side-question: should I expect the value of Document.getDocumentURI() be 
preserved after cloning?  Because that value appears to be discarded.

Assuming it is to be expected, I figured that I could recover the original 
"Attr.getSpecified == false" by performing in-memory validation based on 
reading the DOM API doc [1][2].  I did this by setting 
DOMConfiguration.setParameter("validate", Boolean.TRUE) (after having first 
set Document.setDocumentURI(systemIdOfParsedDocument) to allow for resolving a 
relatively defined DTD) and calling Document.normalizeDocument().

The validation appears to succeed (no errors are reported), but I still get 
"Attr.getSpecified() == true" for defaulted attributes that didn't explicitly 
exist in the XML.  Is this a bug, or is it simply not possible to recover this 
information after a clone that sets these Attrs as "specified == true", even 
using in-memory validation?

I'd like to be able to preserve the "specified" state in the clone so that 
when the document is serialized, I can avoid printing these attributes by 
skipping those with "specified == false".  Seems to me this should be 
possible.  If not, why not?


[1] 
http://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Attr.html#getSpecified%28%29
[2] http://docs.oracle.com/javase/7/docs/api/org/w3c/dom/DOMConfiguration.html


thanks,

Jake
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.