thanks,
- Charles
The XML recommendation is clear about that: The document type
declaration is optional. tDOM doesn't need one; if the document is
well-formed, it will parse your data, even without document type
declaration.
If you create XML, to deliver that XML to an external
system/application, then that system may require one.
>If I do, I don't see a tdom arg to create it, or when I write my xml
>out to a file should I make it my first line?
If you want (or need) one, just [puts] it to your output channel
before you do the [puts .. [$doc asXML ..]].
rolf
The main thing the declaration helps with is determining the encoding of
a stream of bytes. But if you already know the encoding (or have a
unicode string, such as Tcl's strings) then the XML declaration has next
to no practical value. Assuming you're not using XML 1.1 or later. ;-)
> If you create XML, to deliver that XML to an external
> system/application, then that system may require one.
If you're writing an XML _document_, it's a good idea to put the XML
declaration in (though I'd suggest omitting the <!DOCTYPE if you can;
DTDs are seriously out of fashion[*]). If you're just writing an element
fragment, leave the declaration out.
Donal.
[* Both XML-Schema and RELAX-NG are better than a DTD, especially for
XML with namespaces... ]
Don't confuse the XML declaration with the document type
declaration. You're right, the main thing about the XML declaration is
to help with determining the encoding of a stream of bytes, while
reading. The original poster asked about writing the document type
declartion.
>> If you create XML, to deliver that XML to an external
>> system/application, then that system may require one.
>
>If you're writing an XML _document_, it's a good idea to put the XML
>declaration in (though I'd suggest omitting the <!DOCTYPE if you can;
>DTDs are seriously out of fashion[*]). If you're just writing an element
>fragment, leave the declaration out.
To refine that a bit: if you're writing an XML document in UTF-8
encoding, then the XML declaration is optional. If you write your
document in another encoding, it is not only a good idea but strongly
recommended (and often (depending on the document content) absolutely
necessary) that you write an XML declaration.
rolf
Thanks again,
charles
Fair point, except I'd go as far as saying that a large majority of XML
documents don't have DTDs and never will have. This is because of the
way that everyone is switching to using namespaces, which really don't
work with DTDs at all well. Only put a DTD in if some important document
consumer absolutely requires it.
> To refine that a bit: if you're writing an XML document in UTF-8
> encoding, then the XML declaration is optional. If you write your
> document in another encoding, it is not only a good idea but strongly
> recommended (and often (depending on the document content) absolutely
> necessary) that you write an XML declaration.
Well, that depends purely on whether you have a byte-oriented or a
character-oriented transport. If you're lucky enough to have the latter
(e.g. a Tcl string or something with accurate MIME types) then the only
thing that the XML decl buys you is more waste. :-)
Donal.