Overview
Features
Download
Documentation
Community
Add-Ons & Services

XML Attributes

Please post support and help requests here.

XML Attributes

Postby cx500tc » 13 Jan 2009, 23:25

I have to create XML files with BIG (as in megs) base64 attributes. I've notice performance issue in doing so. Although I haven't profile the code I believe the major bottle neck is Poco::XMLWriter::writeAttributes uses characters() to apply encoding and so forth which I could do without giving it's base64 data. Using writeXML(string) instead of characters() would, I believe, make a big difference given that characters() ends up calling writeXML(char) for each characters.

Is rewriting my own version of startElement(..., attributes) my only option? Seems like a lot of work as most of the stuff I would need is private in XMLWriter, would have to duplicated most of it.
cx500tc
 
Posts: 26
Joined: 24 Sep 2007, 17:48

Re: XML Attributes

Postby alex » 14 Jan 2009, 00:56

cx500tc wrote:Is rewriting my own version of startElement(..., attributes) my only option? Seems like a lot of work as most of the stuff I would need is private in XMLWriter, would have to duplicated most of it.


I'm not familiar with the topic at hand (Guenter will have the last word there), but generally speaking if your improvement makes sense (and you needing it in real life indicates it likely does), we'd certainly be happy to see it as a contribution to POCO. So, post your patch on SF tracker and see where it goes.
alex
 
Posts: 1130
Joined: 11 Jul 2006, 16:27
Location: United_States

Re: XML Attributes (SOLVED)

Postby cx500tc » 14 Jan 2009, 01:17

What do you know, it was far more simple then I first though and as I suspected replacing characters() by writeXML() make it twice as fast. Getting rid of addAttributes() will I'm sure also help.

If only XMLWriter::writeXML( const char *data, size_t size ) existed I could save some conversion from char* to std::string.

Code: Select all
   
   startElement(empty, empty, tag, emptyAttributes);
   addAttributes(attributeMap, attrs, empty);
   customWriteAttributes(attributeMap );
   endElement(empty, empty, tag);

...
   void customWriteAttributes(const Poco::XML::XMLWriter::AttributeMap& attributeMap)
   {
      const std::string aMARKUP_EQQUOT      = "=\"";
      const std::string aMARKUP_QUOT        = "\"";
      const std::string aMARKUP_SPACE       = " ";

      for (Poco::XML::XMLWriter::AttributeMap::const_iterator it = attributeMap.begin(); it != attributeMap.end(); ++it)
      {
         writeMarkup(aMARKUP_SPACE);
         writeXML(it->first);
         writeMarkup(aMARKUP_EQQUOT);
         writeXML(it->second); // this used to be characters()
         writeMarkup(aMARKUP_QUOT);
      }
   }

cx500tc
 
Posts: 26
Joined: 24 Sep 2007, 17:48

Re: XML Attributes

Postby cx500tc » 14 Jan 2009, 01:45

For those that care:

Got even more speed, 12 times faster:

I changed

writeXML ( value );

to :

m_str.write ( (const char *)value.data(), value.length( ) ); // m_str is a copy of the stream passdown to XMLWwriter

This bypassed the text encoding all together. Awesome that Poco and C++ allows me to this. I wish I can write code as nice and clean as Poco one day ;-)
cx500tc
 
Posts: 26
Joined: 24 Sep 2007, 17:48


Return to Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron