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 Johannes Stamminger <Jo...@ASTRIUM-Space.com> on 2000/10/12 18:53:35 UTC

Prob: Attribute defaults not serialized(?)

Hi,

I'm having some trouble with attribute defaults being defined in a DTD.
After writing the DOM tree to a file, they do not occur.

BUT: the DOM tree DOES contain this in the DocumentImpl-object data
structure. While debugging I found my attribute with the default value
in
parser->fDocument->docElement->attributes->nodes->elementData[x]->name
and
...->elementData[x]->firstChild->data

After parsing I write the DOM to some file using:

OutputFormat validDocFormat = new OutputFormat(validDoc, "UTF-8", true);
StringWriter validDocStr = new StringWriter();
XMLSerializer validDocSer = new XMLSerializer(validDocStr,
validDocFormat);
validDocSer.asDOMSerializer();
validDocSer.serialize(validDoc);
tmpWrite.write(validDocStr.toString());
tmpWrite.close();

After serialization the StringBuffer does NOT contain the a.m. attribute
:-(.

I disabled the defer-node-expansion feature to get the fDocument field
filled in the DOM tree in the debugger! (Enabling makes no difference).
Validation is enabled and the document is really valid against the used
DTD (using a very restrictive error handler (TESTED!)).

I tried with several Xerces/XML4J versions and JDK-1.2.2 (always binary
dists) on a SPARC Solaris (2.6+Patches) machine.

In the archive of the last two moths I did not find some hints
concerning this except some schema-support problem (which I think I do
not use - Newbie ;-)).


Bug (in XMLSerializer?) / not supported / using error?

If it helps I may extract some snippets ...


J. Stamminger

Re: Prob: Attribute defaults not serialized(?)

Posted by Johannes Stamminger <Jo...@ASTRIUM-Space.com>.
Hi!

> The serializer only prints specified attributes, i.e. attributes that have
> been set to a value within the document. Default attributes are skipped,
> they can be deducted from the DTD/Schema.
> 
> If you look at the code you will see that attributes are printed only if
> attr.getSpecified() is true.

So it is a feature, not a bug (?). Thinking about it one night, I came
to the conclusion, that this could make sense - as long as the parsers
always deduct this from the DTD.

Unfortunately this does not take place (e.g. in non-validating mode)
:-(.

After generating the XML file, I use XT (build v19991105) for some
transformations (B2B App). I set set parameters a way, that it uses the
(same) Xerces-J SAXParser. But the callback handler does not get to see
the default parameters. I guess, because the XT does not validate, but I
have to examine.


Thanks for quick answer!

JOhannes
-- 
// Johannes@Stammingers.de//         _ 
------ ----<--{(@ ---------    /\ .-**)   ASTRIUM - Space Infrastructure
Euckenstr. 25, 28201 Bremen    || `-;()~~  SW Entw.- & Testsyst. (IO 62)
+49 421 556713 (Tel & FAX)     ||+-( )+  Huenefeldstr. 1-5, 28199 Bremen
www.Stammingers.de/../jstammi /##\ /~\       +49 421 539 4152 / FAX 4378

Re: Prob: Attribute defaults not serialized(?)

Posted by Assaf Arkin <ar...@intalio.com>.
The serializer only prints specified attributes, i.e. attributes that have
been set to a value within the document. Default attributes are skipped,
they can be deducted from the DTD/Schema.

If you look at the code you will see that attributes are printed only if
attr.getSpecified() is true.

arkin


On Thu, 12 Oct 2000, Johannes Stamminger wrote:

>  Date: Thu, 12 Oct 2000 18:53:35 +0200
>  From: Johannes Stamminger <Jo...@ASTRIUM-Space.com>
>  Reply-To: xerces-j-dev@xml.apache.org,
     "Stamminger, Johannes" <JO...@ASTRIUM-Space.com>
>  To: XERCES-J Mailing List <Xe...@xml.apache.org>
>  Subject: Prob: Attribute defaults not serialized(?)
>  
>  Hi,
>  
>  I'm having some trouble with attribute defaults being defined in a DTD.
>  After writing the DOM tree to a file, they do not occur.
>  
>  BUT: the DOM tree DOES contain this in the DocumentImpl-object data
>  structure. While debugging I found my attribute with the default value
>  in
>  parser->fDocument->docElement->attributes->nodes->elementData[x]->name
>  and
>  ...->elementData[x]->firstChild->data
>  
>  After parsing I write the DOM to some file using:
>  
>  OutputFormat validDocFormat = new OutputFormat(validDoc, "UTF-8", true);
>  StringWriter validDocStr = new StringWriter();
>  XMLSerializer validDocSer = new XMLSerializer(validDocStr,
>  validDocFormat);
>  validDocSer.asDOMSerializer();
>  validDocSer.serialize(validDoc);
>  tmpWrite.write(validDocStr.toString());
>  tmpWrite.close();
>  
>  After serialization the StringBuffer does NOT contain the a.m. attribute
>  :-(.
>  
>  I disabled the defer-node-expansion feature to get the fDocument field
>  filled in the DOM tree in the debugger! (Enabling makes no difference).
>  Validation is enabled and the document is really valid against the used
>  DTD (using a very restrictive error handler (TESTED!)).
>  
>  I tried with several Xerces/XML4J versions and JDK-1.2.2 (always binary
>  dists) on a SPARC Solaris (2.6+Patches) machine.
>  
>  In the archive of the last two moths I did not find some hints
>  concerning this except some schema-support problem (which I think I do
>  not use - Newbie ;-)).
>  
>  
>  Bug (in XMLSerializer?) / not supported / using error?
>  
>  If it helps I may extract some snippets ...
>  
>  
>  J. Stamminger
>  
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: xerces-j-dev-unsubscribe@xml.apache.org
>  For additional commands, e-mail: xerces-j-dev-help@xml.apache.org
>  

----------------------------------------------------------------------
Assaf Arkin                                          arkin@intalio.com
CTO,  Intalio Inc.                                     www.intalio.com
The Business Process Management Company                 (650) 345 2777