Hi,
Creating a new DOMDocument, supplying any namespace-argument different than zero, results in DOM-tree/serialization inconsistencies (see examples below).This is correct behavior. A DOM tree does not need an xmlns attribute to tell it what namespace an element is in. In fact, namespace attrs are a parse time thing. They are completely ignored after parse.
With xml-parsed DOMDocuments, the document's root element contains the xmlns-attribute, if given in the xml-file. In contrary, newly created DOMDocuments' root elements never contain the xmlns-attribute, although a namespace-argument was given to createDocument, but the DOMWriter-serialized output shows the xmlns-attribute, as expected. This is inconsistent.
Even worse: adding the xmlns-attribute manually to the root element after creation, the serialized output shows the xmlns-attribute twice, which is illegal with respect to the XML specification.This is indeed incorrect. Could you provide the xml file and code that produces this?
The only workaround would be to always set the namespace-argument of DOMImplementationLS::createDocument to zero and to add the xmlns-attribute manually.This is correct behavior. The DOMWriter "fixes" the xmlns on the way out so you can parse it again and get the same document.
Here's some examples that show the spot:
implementation: valid DOMImplementationLS-object-pointer writer: valid DOMWriter-object-pointer namespace: XMLCh-representation of a namespace name root_name: XMLCh-representation of the root element name xmlns: XMLCh-representation of "xmlns"
CASE 1:
DOMDocument *doc = implementation->createDocument(namespace, root_name, 0);
DOMElement *elem = doc->getDocumentElement();
XMLCh *serialized = writer->serialize(elem);
o elem contains no attributes (e.g. elem->hasAttributes() returns false resp. elem->getAttributes() is empty)
o serialized shows the provided xmlns-attribute
What is namespace in this case? Are you aware that it has to be something specific to count as a namespace attr? It is a common mistake to think that xmlns attrs are required when you are creating a document in memory. They are not. The serializer will sort that out for you. The only time you would create them is if you wanted to bind specific prefixes or give a specific default namespace.CASE 2:
DOMDocument *doc = implementation->createDocument(namespace, root_name, 0);
DOMElement *elem = doc->getDocumentElement();
elem->setAttribute(xmlns, namespace);
XMLCh *serialized = writer->serialize(elem);
o elem contains the xmlns-attributes o serialized shows the xmlns-attribute TWICE, which is invalid!
Cheers,
Gareth
--
Gareth Reakes, Managing Director Parthenon Computing
+44-1865-811184 http://www.parthcomp.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]