Re: XmlSerialzier

Aleksander Slominski <[email protected]>
Newsgroups gmane.text.xml.xmlpull.devel
Message-ID <[email protected]>
Stefan Haustein wrote:

> > 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 '').
>
> yes, but for consitency with the parser, "no prefix" should be
> "null"; but then, for getPrefix we have a problem: What to return
> from getPrefix (namespace) in the case of
>
> - no prefix defined vs.
> - no prefix; given namespace is default namespace?

hi,

AFAIK attribute can not be in default namespace!
so for handling namespace in XML there there are two cases:

* in case of attributes: attribute can not be in default namespace so as described in:
http://www.xmlpull.org/v1/doc/api/org/xmlpull/v1/XmlPullParser.html#getAttributeNamespace(int)
returning empty string means that attribute has NO_NAMESPACE

* in case of  elements when element is in default namespace we may return
empty string but in this case it means default empty namespace
(that is  pretty much equivalent to having no namespace)
http://www.xmlpull.org/v1/doc/api/org/xmlpull/v1/XmlPullParser.html#getNamespace()

therefore we never return 'null' for namespace in XmlPullParser
but empty string.

so i think that in XmlSerializer we should have similiar approach:
* prefix and namespace must be always not null for setPrefix()
* and getPrefix() will return null only when

i have updated XmlSerializer javadoc - please take a look and let me know
what you think about it.

thanks,

alek

    /**
     * Binds the given prefix to the given namespace.
     * This call is valid for the next element including child elements.
     * The prefix and namespace MUST be always declared even if prefix
     * is not used in element (startTag() or attribute()) - for XML 1.0 infoset
     * it must result in declaring <code>xmlns:prefix='namespace'</code>
     * (or <code>xmlns:prefix="namespace"</code> depending what character is used
     * to quote attribute value).
     *
     * <p><b>NOTE:</b> this method MUST be called directly before startTag()
     *   and if anything but startTag() or setPrefix() is called next there will be exception.
     * <p><b>NOTE:</b> prefixes "xml" and "xmlns" are already bound
     *   and can not be redefined see:
     * <a href="http://www.w3.org/XML/xml-names-19990114-errata#NE05">Namespaces in XML Errata</a>.
     */
    public void setPrefix (String prefix, String namespace) throws IOException;

    /**
     * Return namespace that corresponds to given prefix
     * If there is no prefix bound to this namespace return null if
     * generatePrefix is false otherwise return generated prefix.
     * <p><b>NOTE:</b> prefixes "xml" and "xmlns" are already bound
     *   will have values as defined
     * <a href="http://www.w3.org/TR/REC-xml-names/">Namespaces in XML specification</a>
     */
    public String getPrefix (String namespace, boolean generatePrefix);
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.