InDesign CS5 Script: How can I ignore the DTD when importing XML?

后端 未结 3 494
渐次进展
渐次进展 2020-12-22 11:37



I am importing XML into InDesign, and I get this message:

The external entity \'blahblah.dtd\' cannot be found. Continue to import anyw

3条回答
  •  -上瘾入骨i
    2020-12-22 12:17

    Ok, even simplier. We just have to prevent interaction and then remove any dtds attached:

    function silentXMLImport(file)
    {
        var doc, oldInteractionPrefs = app.scriptPreferences.userInteractionLevel;
    
        if ( !(file instanceof File) || !file.exists )
        {
            alert("Problem with file : "+file );
        }
    
        if ( app.documents.length == 0 )
        { 
            alert("Open a document first");
            return; 
        }
    
        //Prevent interaction and warnings
        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
        doc = app.activeDocument;
        doc.importXML ( file );
    
        //Remove any dtd attached to the document
        doc.dtds.everyItem().remove();
    
        app.scriptPreferences.userInteractionLevel = oldInteractionPrefs;
    }
    
    //Now import xml
    silentXMLImport ( File ( Folder.desktop+"/foobar.xml" ) );
    

    It's working here.

提交回复
热议问题