簡體   English   中英

使用命令行驗證多個 DITA XSD 1.1 文件(文件夾)使用 Saxon

[英]Using the command line to validate multiple DITA XSD 1.1 files (folder) using Saxon

當我運行 Saxon 命令行來驗證多個 DITA 文件時:

a) 對文件夾使用 -s 選項不起作用。 b) 對文件使用通配符可以,但僅限於單一主題類型:

C:\Users\542470>java -cp C:\Tools\SaxonEE11-3J\saxon-ee-11.3.jar com.saxonica.Validate -catalog:C:\Tools\dita-schemas\catalog-dita.xml -xi:on -xsiloc:on -xsdversion:1.1 "C:\Tools\SaxonEE11-3J\garage\tasks\*"
Saxon license expires in 25 days
Warning at xs:import on line 42 column 73 of softwareDomain.xsd:
  SXWN9018  The schema document at urn:oasis:names:tc:dita:xsd:xml.xsd:1.3 is not being read
  because schema components for this namespace are already available
Warning at xs:import on line 42 column 73 of uiDomain.xsd:
  SXWN9018  The schema document at urn:oasis:names:tc:dita:xsd:xml.xsd:1.3 is not being read
  because schema components for this namespace are already available
Warning at xs:import on line 63 column 73 of commonElementMod.xsd:
  SXWN9018  The schema document at urn:oasis:names:tc:dita:xsd:xml.xsd:1.3 is not being read
  because schema components for this namespace are already available
Warning at xs:import on line 31 column 78 of topicMod.xsd:
  SXWN9018  The schema document at urn:oasis:names:tc:dita:xsd:ditaarch.xsd:1.3 is not being
  read because schema components for this namespace are already available. To force the
  schema document to be read, set --multipleSchemaImports:on
Error on line 13 column 11 of garagetaskoverview.dita:
  XQDY0084  One validation error was reported: Cannot validate <Q{}**concept**>: no element
  declaration available

在這種情況下,所有主題都經過驗證沒有錯誤,但主題未被識別。 我正在使用 DITA-OT/Oxygen garage DITA 示例來測試命令行。 驗證單個 DITA 文件不會出現問題。 只有在同一文件夾中混合 DITA 主題類型時才會發生這種情況。

使用的 DITA 主題類型:

<concept id="taskconcept" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:oasis:names:tc:dita:xsd:concept.xsd:1.3"
    xml:lang="en-US">...

<task id="changeoil" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:oasis:names:tc:dita:xsd:task.xsd:1.3"
    xml:lang="en-US">...

注意:擁有數千個文件會消除列出要驗證的文件的選項。

所有 DITA XML 模式都沒有命名空間,如果 Saxon 有某種模式緩存,一旦它為第一個驗證任務加載“urn:oasis:names:tc:dita:xsd:task.xsd:1.3”模式,它考慮到沒有命名空間它已經有一個架構,因此它可能會重新使用“task.xsd”的架構來驗證概念文件。 我沒有看到避免在命令行中使用此架構緩存的設置。 也許您可以嘗試在 Windows bat 文件中使用“for”循環迭代文件夾中的所有文件,並為每個文件運行驗證過程,而不是對整個文件夾運行驗證。 您也可以直接在 Saxonica 用戶列表上詢問有關此緩存的建議。

我不是 DITA 專家,但我認為所有 DITA 模式模塊都相互兼容,因為您可以將任何選擇的模塊組合到一個模式中。 例如,您可以為要使用的 DITA 模塊的任何子集編寫一個包含xs:include的模式文檔。 我建議在 Saxon validate 命令的 -xsd 選項中使用這樣的復合模式。

或者,嘗試使用選項 --multipleSchemaImports:on - 這應該會導致 Saxon 為特定命名空間(或 null 命名空間)加載模式模塊,即使它已經加載了該命名空間的模式模塊。 (但請注意,如果兩個模式模塊具有重疊定義,這可能會導致失敗——我不知道這是否適用於 DITA。)

但是,如果您編寫一個小的 Java 應用程序來重復調用 Saxon,而不是嘗試從命令行在單個命令中執行所有操作,那么您將對這樣的任務有更多的控制權。

我終於在批處理文件中做了一個“for 循環”。

命令行:batch-validate C:\XML-WORK\repair\DITA-xsd\topics > testlog.txt 2> testerrors.txt

批處理文件命令:對於 (*) 中的 %%i,執行 java com.saxonica.Validate -catalog:C:\Tools\dita-schemas\catalog-dita.xml -xi:on -xsiloc:on -xsdversion:1.1 %%我

注意:將類路徑設置為 Saxon,並將 Dir (CD) 更改為要在運行批處理文件之前驗證的文件夾

驗證大約 4,000 個文件花費了 3 個多小時。 我使用的是 Saxon 的試用版。 如果這始終是預期的結果,則使用批處理文件是不可行的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM