【问题标题】:Problems after changing from saxon 9 enterprise to home edition从 Saxon 9 企业版改为家庭版后的问题
【发布时间】:2016-01-14 10:59:28
【问题描述】:

我们使用的是萨克森企业版。现在我们不再拥有许可证,因此我不得不从应用程序中删除一个 jar 文件 (saxon9ee)。

当我删除这个 jar 文件并添加一个 saxon9-he 时,我们的一个函数停止工作。我们有一个链接可以创建一个包含产品的 xml 文件和 然后在网站上以 html 格式发布。 xml 文件仍在创建,但发布部分失败。它只是显示一个空白页面。

只要我添加了 saxon9ee,它就会再次工作。但是我们不能再使用这个jar - 文件了。

因此,我想这与 DOMSource(XSLT?)的转换有关,但我不能 找出由于丢失 Saxon9ee 而导致的故障部分。我没有例外。有什么好的方法吗 替换我因删除 saxon 企业版而丢失的功能?

代码:

public String publishXmlFile(AS400 as400) {
        try {

            init();

            build();

            CatalogListController ac = (CatalogListController) FacesUtils.getManagedBean(BeanNames.CATALOG_LIST_CONTROLLER);
            Catalog catalog = new Catalog(ac.getSelectedCatalog().getCatalogUi());
            addCatalog(catalog);

            String ifsPath = ApplicationProperties.getString("AS400ExportPath") + "internal/";

            String fileName = ifsPath + ac.getSelectedCatalog().getUrlCode() + ".xml";

            IFSFile xmlFile = new IFSFile(as400, fileName);


            if (!xmlFile.exists()) {
                xmlFile.createNewFile();
            }

            if (xmlFile.exists()) {
                xmlFile.setCCSID(1208);
                IFSFileOutputStream fos;

                try {

                    fos = new IFSFileOutputStream(xmlFile);

                    // Prepare the DOM document for writing
                    Source source = new DOMSource(document);

                    // Prepare the output file

                    Result result = new StreamResult(fos);

                    // Write the DOM document to the file
                    Transformer xformer = TransformerFactory.newInstance().newTransformer();
                    xformer.setOutputProperty("encoding", "utf-8");
                    xformer.setOutputProperty(OutputKeys.INDENT, "yes");

                    xformer.transform(source, result);

                    System.out.println(source.toString() + " " + result.toString());

                    System.out.println("XML-FILE: " + xmlFile.toString());

                    fos.close();

                    xmlFile = null;
                } catch (TransformerConfigurationException e) {
                    e.printStackTrace();
                } catch (TransformerException e) {
                    e.printStackTrace();
                }

            } else {
                System.out.println(xmlFile.getAbsolutePath() + " ");

            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

intit() 函数:

private void init() {
    // Setup Doc
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        document = builder.newDocument();
        document.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\" ");
        domRoot = (Element) document.createElement("xKml");
        document.appendChild(domRoot);
        domRoot.setAttribute("xsi:schemaLocation",  "urn:company:xKml:2:0 http://www99.company.com/schemas/xKml-2-0/xKml-2-0.xsd");
        domRoot.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
        //domRoot.setAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
        domRoot.setAttribute("xmlns", "urn:company:xKml:2:0");

        timeFormatter.setTimeZone(TimeZone.getDefault());
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
}

xsd 文件 (http://www99.company.com/schemas/xKml-2-0/xKml-2-0.xsd):

<xsd:schema targetNamespace="urn:company:xKml:2:0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="2:0">
    <xsd:include schemaLocation="../xKml-2-0-1/common/xKml-Components-2-0-1.xsd"/>

    <!--xsd:include schemaLocation="common/xKml-CommonComponents-2-0.xsd"/
    -->

    <xsd:include schemaLocation="../xKml-2-0-1/Order-2-0-1.xsd"/>
    <xsd:include schemaLocation="../xKml-2-0-1/Invoice-2-0-1.xsd"/>
    <xsd:include schemaLocation="../xKml-2-0-1/Catalog-2-0-1.xsd"/>
    <xsd:include schemaLocation="../xKml-2-0-1/PurchaseForecast-2-0-1.xsd"/>
    <xsd:include schemaLocation="../xKml-2-0-1/OrderResponse-2-0-1.xsd"/>
    <xsd:include schemaLocation="../xKml-2-0-1/OrderChanges-2-0-1.xsd"/>
    <xsd:include schemaLocation="../xKml-2-0-1/ControlMessage-2-0-1.xsd"/>

    <!--

    <xsd:include schemaLocation="documents/xKml-OrderDocument-2-0.xsd"/>
    <xsd:include schemaLocation="documents/xKml-InvoiceDocument-2-0.xsd"/>
    <xsd:include schemaLocation="documents/xKml-CatalogDocument-2-0.xsd"/>
    <xsd:include schemaLocation="documents/xKml-PurchaseForecastDocument-2-0.xsd"/>
    <xsd:include schemaLocation="documents/xKml-OrderResponseDocument-2-0.xsd"/>
    <xsd:include schemaLocation="documents/xKml-OrderChangesDocument-2-0.xsd"/>
    <xsd:include schemaLocation="common/xKml-ControlWorkdataMessages-2-0.xsd"/>

--><!--                 -->
<!-- xKml   -->
<!--                    -->
<xsd:element name="xKml">
    <xsd:complexType>
        <xsd:sequence>
            <xsd:element ref="Version"/>
            <xsd:element ref="History"/>
            <xsd:choice>
                <xsd:sequence>
                    <xsd:element ref="Parameter" minOccurs="0" maxOccurs="unbounded"/>
                    <xsd:element ref="Interchange"/>
                    <xsd:element name="Documents">
                        <xsd:complexType>
                            <xsd:sequence>
                                <xsd:choice>
                                    <xsd:element ref="Catalog" minOccurs="0" maxOccurs="unbounded"/>
                                    <xsd:element ref="PurchaseForecast" minOccurs="0" maxOccurs="unbounded"/>
                                    <xsd:element ref="Order" minOccurs="0" maxOccurs="unbounded"/>
                                    <xsd:element ref="OrderResponse" minOccurs="0" maxOccurs="unbounded"/>
                                    <xsd:element ref="OrderChanges" minOccurs="0" maxOccurs="unbounded"/>
                                    <xsd:element ref="Invoice" minOccurs="0" maxOccurs="unbounded"/>
                                </xsd:choice>
                            </xsd:sequence>
                        </xsd:complexType>
                    </xsd:element>
                </xsd:sequence>
                <xsd:element ref="ControlMessage"/>
            </xsd:choice>
        </xsd:sequence>
    </xsd:complexType>
</xsd:element>
</xsd:schema>

build() 函数:

private void build() {
        Element e, e1, e2, e3;

        // basic sceleton for DOMtree
        e = (Element) document.createElement("Version");
        e.setAttribute("xmlns", "urn:company:xKml:2:0");
        domRoot.appendChild(e);
        e.appendChild(document.createTextNode("02.00"));

        e = (Element) document.createElement("History");
        e.setAttribute("xmlns", "urn:company:xKml:2:0");
        domRoot.appendChild(e);

        e1 = document.createElement("HistoryRecord");
        e1.setAttribute("xmlns", "urn:company:xKml:2:0");
        e.appendChild(e1);

        e2 = document.createElement("Process");
        e2.setAttribute("xmlns", "urn:company:xKml:2:0");
        e1.appendChild(e2);
        e2.appendChild(document.createTextNode("B2B"));

        e2 = document.createElement("Timestamp");
        e2.setAttribute("xmlns", "urn:company:xKml:2:0");
        e1.appendChild(e2);

        e3 = document.createElement("Date");
        e3.setAttribute("xmlns", "urn:company:xKml:2:0");
        e2.appendChild(e3);
        e3.appendChild(document.createTextNode(dateFormatter.format(new Date())));

        e3 = document.createElement("Time");
        e3.setAttribute("xmlns", "urn:company:xKml:2:0");
        e2.appendChild(e3);
        e3.appendChild(document.createTextNode(timeFormatter.format(new Date())));

        e = (Element) document.createElement("Interchange");
        e.setAttribute("xmlns", "urn:company:xKml:2:0");
        domRoot.appendChild(e);

        e1 = document.createElement("InterchangeIdentity");
        e1.setAttribute("xmlns", "urn:company:xKml:2:0");
        e.appendChild(e1);
        e1.appendChild(document.createTextNode(dateFormatter.format(new Date()) + " "  + timeFormatter.format(new Date())));

        e1 = document.createElement("Timestamp");
        e1.setAttribute("xmlns", "urn:company:xKml:2:0");
        e.appendChild(e1);

        e2 = document.createElement("Date");
        e2.setAttribute("xmlns", "urn:company:xKml:2:0");
        e1.appendChild(e2);
        e2.appendChild(document.createTextNode(dateFormatter.format(new Date())));

        e2 = document.createElement("Time");
        e2.setAttribute("xmlns", "urn:company:xKml:2:0");
        e1.appendChild(e2);
        e2.appendChild(document.createTextNode(timeFormatter.format(new Date())));

        e1 = document.createElement("ComPartners");
        e1.setAttribute("xmlns", "urn:company:xKml:2:0");
        e.appendChild(e1);

        e2 = document.createElement("From");
        e2.setAttribute("xmlns", "urn:company:xKml:2:0");
        e1.appendChild(e2);

        e2 = document.createElement("To");
        e2.setAttribute("xmlns", "urn:company:xKml:2:0");
        e1.appendChild(e2);

        e1 = document.createElement("DeploymentMode");
        e1.setAttribute("xmlns", "urn:company:xKml:2:0");
        e.appendChild(e1);

        e1.appendChild(document.createTextNode("Operational"));


    }

addCatalog() 使用与 build() 相同的方法和标准。

在它工作的应用程序版本中,我有这些罐子:

saxon9-icu.jar
saxon9-sql.jar
saxon9-stats.jar
saxon9ee-test.jar
saxon9ee.jar
saxon-license.lic

在没有企业版的情况下不起作用:

saxon9-dom.jar
saxon9-icu.jar
saxon9-sql.jar
saxon9-stats.jar
saxon9-test.jar
saxon9-xqj.jar
saxon9.jar
saxon9he.jar

我必须做些什么来替换撒克逊语中缺少的功能?它是哪一部分?

谢谢

【问题讨论】:

  • 那么你到底得到了哪些错误?据我所知,Saxon HE 确实允许您转换 DOMSource,所以这应该不是问题。
  • 我没有错误。没有企业版,页面只是空白。我想我需要企业 jar 文件中的一些特定功能,但我无法确切知道替换它是什么或如何替换它。家庭版支持 XSLT 2.0 但不支持 3.0 作为企业版。这可能是问题吗?如何解决这个问题?如果这是问题所在,是否还有其他支持 3.0 的 XSLT 处理器?我没有编写此应用程序的代码,因此我不太了解代码。谢谢
  • 但是Transformer xformer = TransformerFactory.newInstance().newTransformer(); 甚至不加载样式表,而只创建一个默认转换器来序列化源,所以我不明白为什么 Saxon HE 甚至 JRE 的内置 Xalan 不应该能够这样做。
  • 是的,这就是为什么我无法弄清楚 Saxon9ee 中的哪个部分可以完成工作:) 因为只要我再次添加 Saxon9ee - jar 文件,它就会工作。 xml 文件的创建工作正常,因此我只能猜测原因必须与 XSLT 相关。我应该寻找什么其他想法?谢谢
  • 您的 XSLT 是否可能正在使用企业功能/特性?您是否尝试过应用一个简单的身份转换来验证它是否正在加载和应用一个非常简单的 XSLT?你能发布你的 XSLT 吗?

标签: java xml xslt saxon


【解决方案1】:

DOM 代码看起来完全错误,您应该使用命名空间感知的 DOM 工厂/构建器,然后使用命名空间感知的 DOM 方法,如 createElementNS 和 setAttributeNS。

【讨论】:

  • 是的,这是正确的答案。我让工厂命名空间知道,然后我将命名空间添加到元素中。属性不需要它。但在此之后我再次尝试,验证了 xml,现在它可以工作了。我不知道为什么撒克逊企业在没有名称空间的情况下支持它。非常感谢大家的帮助!
  • 我也不知道。访问 DOM 是个谜。最糟糕的事情之一是,Saxon 无法发现提供的 DOM 是否支持命名空间,即使我们需要知道才能正确访问它。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 1970-01-01
  • 2016-02-29
相关资源
最近更新 更多