Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java XML-22003:(错误)无法写入输出流_Java_Xml_Xslt - Fatal编程技术网

Java XML-22003:(错误)无法写入输出流

Java XML-22003:(错误)无法写入输出流,java,xml,xslt,Java,Xml,Xslt,我在尝试使用Java从XMLStylesheet生成XMLs时遇到XSL异常“XML-22003:(错误)无法写入输出流”。输出XML的位置是在运行时使用参数集在样式表中动态定义的。 此外,XML是在样式表的位置生成的,但我只想在指定的位置生成它。 我尝试了很多,但似乎只有我一个人犯了这个错误 下面是用于设置位置参数和处理样式表的Java代码的快照: XSLProcessor processor = new XSLProcessor(); XSLStylesheet xsl =null; //

我在尝试使用Java从XMLStylesheet生成XMLs时遇到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);
<?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">
下面是XMLStylesheet的快照:

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);
<?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).
发生XSL异常:文件:/C:/PMTData/featureSpecification\u dpc.XSL:XML-22003:(错误)无法写入输出流(C:/PMTData/FinalXMLs/featureSpecification/featureSpecification\u c040116\u A.101.XML)。
我一直在尝试各种硬编码的位置,终于出乎意料地开始工作了。我不知道怎么做。我试图生成输出XML的位置肯定是个问题。因为我在一个Web项目中进行此活动,所以我给出了服务器的位置(我之前也尝试过,但没有成功,可能我错过了一些东西)。现在,它可以在指定的服务器位置生成XML。

您需要提供一些代码,以便我们能够重现您的错误/了解您的用例。我已经更新了代码快照、样式表和收到的错误。如果您能看一看,我将不胜感激。您是否尝试了
文件
URI格式的
文件:/C:/PMTData/FinalXMLs/FeatureSpecification/FeatureSpecification\u c041116\u a.101.xml
作为
href
属性?我尝试将参数更改为:String filenamePath=“文件:/c:/PMTData/FinalXMLs/”+tmpIccName+“/”,但得到相同的错误文件:/c:/code\ws/PMTData/featureSpecification\u dpc.xsl:XML-22003:(错误)无法写入输出流('file:/c:/PMTData/FinalXMLs/featureSpecification/'featureSpecification\u C0401116\u A.101.XML)。使用XSLT处理器是否可以将文件写入其他位置?可能是访问被拒绝/权限问题。恐怕我不熟悉(Oracle?)处理器,XSLT 2看起来不错。