comments on XML Pull Parsing presentation

Aleksander Slominski <[email protected]>
Newsgroups gmane.text.xml.xmlpull.devel
Message-ID <[email protected]>
hi Elliotte,

i looked on your presentation:

  http://www.ibiblio.org/xml/slides/sd2002east/xmlpull/XML_Pull_Parsing.html

and i noteiced really nice collection of useful sample programs
that use XmlPull API - if you want we can add them to standard
XmlPull samples.

here are my few comments about code smaples from presentation:
in http://www.ibiblio.org/xml/slides/sd2002east/xmlpull/32.html
instead of:

      for (int event = parser.next();
           event != XmlPullParser.END_DOCUMENT ;
            event = parser.next()) ;

it is much shorter and easier to understand to write this loop like this:

    while( parser.next() != XmlPullParser.END_DOCUMENT);


and answering question "How to define attribute prefixes????" from:

  http://www.ibiblio.org/xml/slides/sd2002east/xmlpull/41.html

you need to modify this code:

         if (event == XmlPullParser.START_TAG) {
             String namespaceURI = parser.getNamespace();
             if (!namespaceURI.equals(RDDL_NS)) {
                 String prefix = parser.getPrefix();
                 if (prefix == null) prefix = "";
                 if (namespaceURI != null) {
                     serializer.setPrefix(prefix, namespaceURI);
                 }
                 serializer.startTag(namespaceURI, parser.getName());
                 // add attributes
                 for (int i = 0; i < parser.getAttributeCount(); i++) {
                     serializer.attribute(
                       parser.getAttributeNamespace(i),
                       parser.getAttributeName(i),
                       parser.getAttributeValue(i)
                     );
                     // How to define attribute prefixes????
                 }
             }
         }

to something looking like this:

         if (event == XmlPullParser.START_TAG) {
             // declare all known prefix-namespace pairs
             for (int i = parser.getNamespaceCount(parser.getDepth()-1); i <
parser.getNamespaceCount(parser.getDepth()); ++i)
                setPrefix(parser.getNamespacePrefix(i), parser.getNamespaceUri(i));
             }
             String namespaceURI = parser.getNamespace();
             if (!namespaceURI.equals(RDDL_NS)) {
                 String prefix = parser.getPrefix();
                 if (prefix == null) prefix = "";
                 if (namespaceURI != null) {
                     serializer.setPrefix(prefix, namespaceURI);
                 }
                 serializer.startTag(namespaceURI, parser.getName());
                 // add attributes
                 for (int i = 0; i < parser.getAttributeCount(); i++) {
                     serializer.attribute(
                       parser.getAttributeNamespace(i),
                       parser.getAttributeName(i),
                       parser.getAttributeValue(i)
                     );
                     // How to define attribute prefixes????
                 }
             }
         }

however this brings aquesiton: why would you want to declare
prefixes at all ? XmlSerializer is optimized for common case when user
want to create valid XML outptu and do not want to worry
about namespace prefixes - so XmlSerializer will generate
prefixes if namespaces need to be declared. therefore
prefixes should only be set manually if you need to minimize
document size or you want to have a better look ...

finally as you already know based on my experience
with writing complex XML code for parsing
i do not agree with "Too few classes; on the flip side
too much is forced into the XmlPullParser class." or "Does not
take advantage of polymorphism"

  http://www.ibiblio.org/xml/slides/sd2002east/xmlpull/43.html

but i think we have this argument set now:

  http://www.xml.com/pub/a/2002/09/25/xmlpull.html

and i think at least some people agree with this point of view:

  http://www.injektilo.org/archives/2002/08/19.html

also use of "Int type codes" is not too bad if you consider
problems that Java typesafe enums have

  http://www.javaworld.com/javaworld/javatips/jw-javatip122.html

thanks,

alek
--
The ancestor of every action is a thought. - Ralph Waldo Emerson



------------------------ Yahoo! Groups Sponsor ---------------------~-->
Get 128 Bit SSL Encryption!
http://us.click.yahoo.com/CBxunD/vN2EAA/xGHJAA/2U_rlB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
[email protected]

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
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.