0



XML を InDesign にインポートすると、次のメッセージが表示されます。

外部エンティティ 'blahblah.dtd' が見つかりません。このままインポートを続行しますか?

XML のインポートを続行すると、次のエラー メッセージが表示されます。

Javascript エラー!

エラー番号: 103237 エラー文字列: DOM 変換エラー: 名前空間が無効です。

エンジン: セッション ファイル: C:\blahblah\blahblah.jsx 行: 259 ソース:
obj.doc.importXML(File(xmlDoc) );

...問題は、DTD にアクセスできないことです。とにかく、私の目的には必要ありません。


  • では、DTD を無視する Extendscript の方法はありますか?
  • そうでない場合、XSLT で DTD を無視する方法はありますか?



関連するコードは次のとおりです。

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

...これは、p. に基づいています。407 (Chapter 18) of InDesign CS5 Automation Using XML & Javascript、Grant Gamble 著

4

3 に答える 3

1

わかりました、さらに簡単です。相互作用を防ぎ、接続されている dtds を削除するだけです。

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

ここで機能しています。

于 2012-08-01T08:17:44.777 に答える
1

zanegrey はあなたに主な概念を与えたと思いますが、あなたは物事を複雑にしすぎていると思います. xml ファイルのコンテンツを取得するだけでなく、正規表現で dtd 宣言を削除してから、入力に使用される新しい XML ファイルを出力するのはなぜですか?

//Open and retrieve original xml file content
var originalXMLFile = File (Folder.desktop+"/foo.xml" );
originalXMLFile.open('r');
var content = originalXMLFile.read();
//Looks for a DOCTYPE declaration and remove it
content = content.replace ( /\n<!DOCTYPE[^\]]+\]>/g , "" );
originalXMLFile.close();
//Creates a new file without any DTD declaration
var outputFile = new File ( Folder.desktop+"/bar.xml" );
outputFile.open('w');
outputFile.write(content);
outputFile.close();

その後、このフィルタリングされた xml をインポートに使用できます。

于 2012-07-31T19:41:22.227 に答える
1

DOCTYPE 宣言を削除する XSLT を次に示します。

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <xsl:copy-of select="."/>
    </xsl:template>
</xsl:stylesheet>
于 2012-07-31T20:08:07.580 に答える