1

So, I've been searching but couldn't find an answer.

There's a question on SOF about creating large XML's causing this Out of Memory exception, but that's not my case.

I'm creating a XML using IXMLDocument via XML Data Binding, and it's created just fine.

But when saving it to file, it's all in one single line of text. The way to go was to passing the XML through FormatXMLData just before saving it to file.

This works great on small files, but crashes with an EOutOfMemory if the XML is large enough.

So I tried adding the option [doNodeAutoIndent], but didn't work either.

Next move, I created a TStringList to receive the XML, so I could deactivate the IXMLDocument, and then try the FormatXMLData on the TSringList. I wasn't expecting much of this, but I figure maybe these two components use different memory manager (am I wrong believing the IXMLDocument uses COM memory manager instead of Delphi's?), and reality came that much close to expectations, as the same exception was raised.

Anyone has an idea of how to have my xml saved correctly indented and formated when using XML Data Binding, either with FormatXMLData or any other option?

Reading similar questions here on StackOverFlow, I saw some alternatives, including a SAX parser to replace DOM based IXMLDocument, but I believe that would disable the advantage of XML Data Binding, isn't it so?

Thank you, Nuno

nunopicado
  • 307
  • 4
  • 17

1 Answers1

1

You do not have to replace the DOM parser with a SAX parser as long as the SAX parser can process the DOM tree string as input stream.

You could also implement your own stream-based formatter which only needs to indent / unindent the string based on opening/closing XML element tags in the string. This would be fast and easy to implement.

mjn
  • 36,362
  • 28
  • 176
  • 378
  • Hi mjn. Thank you for replying. So you suggest I create the XML using the DOM parser with the XML Data Binding, and then pass the XML string to the SAX parser, or a custom made indenter, just to format the XML, is this right? That's a thought... Do you know any SAX parser (for XE3) that you could recommend? I'd like to check that option out... – nunopicado Feb 17 '14 at 13:28