SAP PO 处理一些特殊字符,比如XML有效载荷内容中的“&”。转换中会引起报错:com.sap.aii.utilxi.misc.api.BaseRuntimeException; Character reference "&#
解决方案:可以通Java Mapping 做一次转换。
import java.io.*;
import java.util.HashMap;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class EscapeSpecialChar extends AbstractTransformation
{
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException
{
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
String inputXML = "";
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputstream));
String temp = "";
while((temp = reader.readLine()) != null)
{
if (temp != null)
inputXML += temp;
}
String outXML = inputXML.replaceAll("&", "&");
outputstream.write(outXML.getBytes());
} catch (Exception eex) {
throw new StreamTransformationException(eex.toString());
}
}
}
文章来源:https://www.toymoban.com/news/detail-462449.html
文章来源地址https://www.toymoban.com/news/detail-462449.html
到了这里,关于SAP PO 中处理特殊字符 & com.sap.aii.utilxi.misc.api.BaseRuntimeException; Character reference “的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!