InDesign CS5脚本:导入XML时如何忽略DTD? [英] InDesign CS5 Script: How can I ignore the DTD when importing XML?

查看:167
本文介绍了InDesign CS5脚本:导入XML时如何忽略DTD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在将XML导入InDesign,并且得到以下消息:



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


找不到外部实体 blahblah.dtd。继续导入
吗?

The external entity 'blahblah.dtd' cannot be found. Continue to import anyway?

然后当我继续导入XML时,出现以下错误消息:

And when I then continue to import the XML, I get this error message:


Javascript错误!

Javascript Error!

错误编号:103237错误字符串:DOM转换错误:无效
命名空间。

Error Number: 103237 Error String: DOM transformation error: Invalid namespace.

引擎:会话文件:C:\blahblah\blahblah.jsx行:259来源:

obj。 doc.importXML(File(xmlDoc));

Engine: session File: C:\blahblah\blahblah.jsx Line: 259 Source:
obj.doc.importXML(File(xmlDoc) );

...问题是,我无法访问DTD,无论如何我都不需要它。



...the problem is, is that I won't have access to the DTD, and I won't need it for my purposes anyway.



  • 因此,有没有一种扩展方法可以忽略

  • 如果没有,是否可以通过XSLT忽略DTD?

  • So, is there a Extendscript way to ignore the DTD?
  • If not, is there a way to ignore the DTD with XSLT?




这是相关代码:



Here is the relevant code:

function importXML(xmlDoc, xslt)
{
    with(obj.doc.xmlImportPreferences)
    {
        importStyle = XMLImportStyles.MERGE_IMPORT; // merges XML elements into the InDesign document, merging with whatever matching content
        createLinkToXML = true; // link elements to the XML source, instead of embedding the XML

        // defining the XSL transformation settings here
        allowTransform = true; // allows XSL transformation
        transformFilename = File(xslt); // applying the XSL here

        repeatTextElements = true; //  repeating text elements inherit the formatting applied to placeholder text, **only when import style is merge!
        ignoreWhitespace = true; // gets rid of whitespace-only  text-nodes, and NOT whitespace in Strings
        ignoreComments = true;
        ignoreUnmatchedIncoming = true; // ignores elements that do not match the existing structure, **only when import style is merge!
        importCALSTables = true; // imports CALS tables as InDesign tables
        importTextIntoTables = true; // imports text into tables if tags match placeholder tables and their cells, **only when import style is merge!
        importToSelected = false; // import the XML at the root element
        removeUnmatchedExisting = false;
    }

    obj.doc.importXML(File(xmlDoc) );
    obj.doc.mapXMLTagsToStyles(); // automatically match all tags to styles by name (after XSL transformation)

    alert("The XML file " + xmlDoc.name + " has been successfully imported!");

} // end of function importXML

...这是基于在第使用XML的InDesign CS5自动化& Javascript ,由Grant Gamble

...this is based on p. 407 (Chapter 18) of InDesign CS5 Automation Using XML & Javascript, by Grant Gamble

推荐答案

好,甚至更简单。我们只需要阻止交互,然后删除所有附加的dtd:

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" ) );

在这里工作。

这篇关于InDesign CS5脚本:导入XML时如何忽略DTD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆