我在尝试使用Java从XMLStylesheet生成XML时遇到XSL异常“XML-22003 :(错误)无法写入输出流”。使用运行时期间的参数集在样式表中动态定义输出XML的位置。 此外,XML是在样式表的位置生成的,但我想仅在指定的位置生成它。 我已经尝试了很多,但似乎我是唯一一个遇到此错误的人。
以下是 Java代码的快照,用于设置location参数和处理样式表:
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).
答案 0 :(得分:0)
我一直在尝试各种硬编码的位置,最后它已经开始工作了。我不知道怎么做。绝对是我尝试生成输出XML的位置是一个问题。由于我在Web项目中执行此活动,因此我给出了服务器的位置(我之前也尝试过但是没有工作,也许我错过了一些东西)。现在它能够在指定的服务器位置生成XML。