【问题标题】:XML-22003: (Error) Unable to write to output streamXML-22003:(错误)无法写入输出流
【发布时间】:2017-11-21 05:38:30
【问题描述】:

我在尝试使用 Java 从 XMLStylesheet 生成 XML 时遇到 XSL 异常“XML-22003:(错误)无法写入输出流”。输出 XML 的位置是在运行时使用参数集在样式表中动态定义的。 此外,XML 是在样式表的位置生成的,但我只想在指定的位置生成它。 我已经尝试了很多,但似乎我是唯一遇到此错误的人。

以下是用于设置位置参数和处理样式表的 Java 代码的快照:

XSLProcessor processor = new XSLProcessor();
XSLStylesheet xsl =null;

//xslURL is the URL of the Stylesheet stored.
xsl = processor.newXSLStylesheet(xslURL);
Transformer xsltTransformer = xsl.newTransformer();
String filenamePath = finalXMLLocation + "PMTFolder/FinalXMLs/";

xsltTransformer.setParameter("filenamePath","'"+ filenamePath + "'");
xsltTransformer.setParameter("itemCodes", "'" + itemCodes + "'");

//DiagramXML is the location of the XML which has to be transformed.
InputStream inputStream = new FileInputStream(diagramXML);
StreamSource in = new StreamSource(inputStream);

final StringWriter stringWriter=new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
StreamResult outputTarget=new StreamResult(printWriter);
xsltTransformer.transform(in, outputTarget);

下面是 XMLStylesheet 的快照:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"   xmlns:xref="http://www.oracle.com/XSL/Transform/java/oracle.tip.xref.xpath.XRefXPathFunctions" xmlns:xp20="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.Xpath20" xmlns:bpws="http://schemas.xmlsoap.org/ws/2003/03/business-process/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ora="http://schemas.oracle.com/xpath/extension" xmlns:ehdr="http://www.oracle.com/XSL/Transform/java/oracle.tip.esb.server.headers.ESBHeaderFunctions" xmlns:orcl="http://www.oracle.com/XSL/Transform/java/oracle.tip.pc.services.functions.ExtFunc" xmlns:ids="http://xmlns.oracle.com/bpel/services/IdentityService/xpath" xmlns:hwf="http://xmlns.oracle.com/bpel/workflow/xpath"  xmlns:ns7="http://xmlns.oracle.com/EnterpriseObjects/Core/CommonEBO/V1" xmlns:ns8="http://xmlns.oracle.com/EnterpriseObjects/Core/Common/V2"  xmlns:ns1="http://xmlns.oracle.com/EnterpriseObjects/Core/EBO/ItemComposition/V1"  xmlns:prodtool="URI:prodtool" exclude-result-prefixes="xsl xref xp20 bpws ora ehdr orcl ids hwf">
    <xsl:output omit-xml-declaration="yes" method="xml" indent="yes" name="xml"/>
    <xsl:param name="filenamePath" value ="c:/code_ws/PMTData/FinalXML"/>

    <xsl:param name="itemCodes"/>
    <xsl:key name="attrModelPath" match="/prodtool:Diagram/pov/attr/atCalcProdAt/AtCalcModPat" use="concat(@productOfferingIdentifier,',',@productOfferingName,',',@productOfferingRelationshipDirection,',',@productOfferingRelationshipType,',',@isRootSalesRelationContext,',',@childProductOfferingIdentifier,',',@childProductOfferingName,',',@productAttributeName,',',@productAttributeDataType)"/>
    <xsl:template match="/">
        <xsl:for-each select="/prodtool:Diagram/pov">
            <xsl:if test="not(contains($itemCodes,@primaryIdentifier))">
                <xsl:variable name="filePath" select="concat($filenamePath,concat(concat(concat('ProductOffering_',@primaryIdentifier),'_'),concat(@version,'.xml')))"/>
                <xsl:result-document href="{$filePath}" format="xml">

以下是我得到的错误:

XSL Exception occured: file:/C:/PMTData/featureSpecification_dpc.xsl<Line 39, Column 57>: XML-22003: (Error) Unable to write to output stream (C:/PMTData/FinalXMLs/FeatureSpecification/FeatureSpecification_C0401116_A.101.xml).

【问题讨论】:

  • 您需要提供一些代码,以便我们重现您的错误/了解您的用例。
  • 我已经更新了代码快照、样式表和我遇到的错误。不胜感激,如果你能看看。
  • 您是否尝试过使用file:/C:/PMTData/FinalXMLs/FeatureSpecification/FeatureSpecification_C0401116_A.101.xml 形式的file URI 来代替href 属性?
  • 我尝试通过将参数更改为: String filenamePath = "file:/c:/PMTData/FinalXMLs/" + tmpIccName + "/";但得到相同的错误文件:/c:/code_ws/PMTData/featureSpecification_dpc.xsl: XML-22003: (Error) Unable to write to output stream ('file:/c:/PMTData/FinalXMLs/ FeatureSpecification/'FeatureSpecification_C0401116_A.101.xml)。
  • 使用 XSLT 处理器是否设法将文件写入不同的位置?也许这是一个访问被拒绝/权限问题。恐怕我不熟悉那个(Oracle?)处理器,XSLT 2 看起来不错。

标签: java xml xslt


【解决方案1】:

我一直在尝试各种硬编码的位置,最后它突然开始工作了。我不知道怎么做。绝对是我试图生成输出 XML 的位置是个问题。由于我在 Web 项目中进行此活动,因此我给出了服务器的位置(我之前也尝试过但没有工作,也许我错过了一些东西)。现在它可以在指定的服务器位置生成 XML。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-25
    • 2011-03-29
    • 1970-01-01
    • 2013-02-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多