Re: XmlSerialzier
Aleksander Slominski <[email protected]>
| Newsgroups | gmane.text.xml.xmlpull.devel |
|---|---|
| Message-ID | <[email protected]> |
Stefan Haustein wrote:
> Great! The only problem I can see is default namespace handling
> in getPrefix; especially, default namespaces do not apply to
> attributes.... any suggestions??
hi,
i think that call to setPrefix("pref", ...) should always result in delcaring prefix namespace
i.e. for XML 1.0 in xmlns:prefix='...' and similarly to change or declre default namespace
simple call setPrefix("", "...") could be used (resulting in xmlns='') - so calling setPrefix("", "")
would always restore default namespace (setting it to 'no namespace' state of '').
so setPrefix("", "urn:namespace") can be used to change default namespace but there is
a potential problem: when startTag() is to be serialized with default namesapce
(ex. startTag("", "foo")) then XmlSerializer has no way to generate prefix for default namespace
(serializing "xnlns:n1=''" is illegal and when parsed by XML 1.0 with namespaces compliant
parser will result in exception).
so i think that in this case the generated prefix must be used for "urn:namespace"
(if no prefix for "urn:namespace" is available) and default namespace must be restored to ""
to be able to write startTag that is in default namespace.
finally attributes can not be declared in default namespace so calling attribute("", "attrName", "value")
will always result in serializing an attribute without namespace and there is no need to find or declare
prefix for it (in XML 1.0 just simply write "attrName=''").
here is an example of how it could work:
startTag("", "foo")
setPrefix("", "urn:namespace"); //chnage default namespae
startTag("unr:namespace", "quo")
startTag("", "bar"); // as defult nemspace is not '' this implicitly causes: setPrefix("", ""),
setPrefix(NEW, "urn:namespace")
attribute("", "attrName", "value")
attribute("urn:namespace", "attr2", "value")
startTag("", "baz")
startTag("urn:namespace", "zoo")
that i think should be serialized as:
<foo>
<quo xmlns='urn:namespace'>
<bar xmlns="" xmlns:n1="urn:namespace" attrName='value' n1:atttr='value'>
<baz>
<n1:zoo>
does it sound reasonable?
thanks,
alek