Skip to main content
Participant
August 5, 2015
Question

Setting XML import option "Do not import contents of whitespace-only elements" programatically

  • August 5, 2015
  • 0 replies
  • 284 views

When importing xml file into an xml element in the document structure, using the 'Merge content' option we have in the next 'XML Options' dialog an option as "Do not import contents of whitespace-only elements".

What I need is to be able to use this option when performing the import programatically. When using 'kImportXMLFileCmdBoss' import options can be changed using the 'IXMLImportOptions' interface, but this interface doesn't contain a method  to set the above mentioned option.

Reading the documentation, 'plugin-programming-guide-vol2.pdf', I found something called 'Sparse Import' that seemed to do what I need; it is described in the docs as follows:

Sparse import

If this feature is turned on during XML import, incoming elements that have no content (or only whitespace for content) do not replace content in the matching existing XML element in the XML template. By default, this feature is turned off.

I set it to true before performing the import using the following code, but it didn't work (it give different result compared to the case when the above mentioned xml import option is set during manual import):

do {

  InterfacePtr<IDocument> document(GetExecutionContextSession()->GetActiveContext()->GetContextDocument(), UseDefaultIID());

  if(!document) {

       break;

  }

  InterfacePtr<IK2ServiceRegistry> serviceRegistry(GetExecutionContextSession(), UseDefaultIID());

  if (!serviceRegistry) {

       break;

  }

  InterfacePtr<IK2ServiceProvider> serviceProvider(

  serviceRegistry->QueryServiceProviderByClassID(kXMLPostImportIterationService,kXMLSparseImportOptionsServiceBoss));

  if (!serviceProvider) {

       break;

  }

  InterfacePtr<IXMLImportPreferences> xmlImportPrefs(serviceProvider, UseDefaultIID());

  if (!xmlImportPrefs) {

       break;

  }

  InterfacePtr<IXMLImportOptionsPool> prefsPool( document->GetDocWorkSpace(), UseDefaultIID() );

  XMLImportPreferencesInitializer initializer(xmlImportPrefs, prefsPool);

  xmlImportPrefs->SetNthPref(0 ,kTrue);

  xmlImportPrefs->CommitChanges();

} while(kFalse);

Note I am developing against InDesign CS6.

Thanks in advance,

Ali

This topic has been closed for replies.