on 08-08-2012 7:53 PM
Dear,
how I can do this with a UDF?
I need to extract, content of (Codigo y Mensaje, but will always have different positions in the xml,
Example1: Codigo: 0 y Mensaje: http://192.168.12.90/Facturacion/PDFServlet?docId=KC4uHbk9PbESoy8lcV(MaS)JrA<
Example1 |
---|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><!-- Request Message Mapping --> <ns:OnlineGenerationDteResponse xmlns:ns='http://webservices.online.webapp.paperless.cl' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><ns:return><?xml version="1.0" encoding="ISO-8859-1"?> <Respuesta> <Codigo>0</Codigo> <Mensaje>http://192.168.12.90/Facturacion/PDFServlet?docId=KC4uHbk9PbESoy8lcV(MaS)JrA</Mensaje> </Respuesta> </ns:return></ns:OnlineGenerationDteResponse> |
Example2: Codigo: -30 y Mensaje: Error, el Emisor informado en el XML, no corresponde a empresa Emisora.
Example2 |
---|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?><!-- Request Message Mapping --> <ns:OnlineGenerationDteResponse xmlns:ns='http://webservices.online.webapp.paperless.cl' xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'><ns:return><?xml version="1.0" encoding="ISO-8859-1"?> <Respuesta> <Codigo>-30</Codigo> <Mensaje>Error, el Emisor informado en el XML, no corresponde a empresa Emisora.</Mensaje> </Respuesta> </ns:return></ns:OnlineGenerationDteResponse> |
Regards,
Hi Pablo,
You can use a simple XSL to disable the inside escaping characters:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:Q-ENV="http://www.quadrem.com/soap/" xmlns:ns="http://webservices.online.webapp.paperless.cl" version="1.0">
<xsl:output method="text" version="1.0" encoding="ISO-8859-1" indent="no" omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:value-of select="ns:OnlineGenerationDteResponse/ns:return" disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
If you test this example with your second XML:
Now, with the XML correct you can use a Message Mapping to extract the "codigo" tag and/or Mensaje" tag:
Operation Mapping:
Message Mapping (You can use the XML output for the source message):
Hope this helps.
(Spanish is my native language too but most people here doesn’t understand it, please write only in english)
Regards.
Message was edited by: Iñaki Vila
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi. Pablo.
You can try with JavaMapping.
public void execute(InputStream in, OutputStream out) throws ParserConfigurationException {
try {
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
DocumentBuilder builderel=factory.newDocumentBuilder();
Document docIn=builderel.parse(in);
Document docOut=builderel.newDocument();
Element MainRoot=docOut.createElement("ns0:Test");//
MainRoot.setAttribute("xmlns:ns0","urn:sap.com.pe:test"); //
String charSet[]={"<",">"};
String replaceSet[]={"<",">"};
NodeList nodeLst = docIn.getElementsByTagName("ns:return");
Node n = null;
Element child1 = null,child2 =null;
for(int nRow=0; nRow < nodeLst.getLength();nRow++ ){
if(nodeLst.item(nRow).hasChildNodes()){
n=nodeLst.item(nRow).getFirstChild();
if(n.getNodeType()== Node.TEXT_NODE ){
String sValor=n.getNodeValue();
for(int j=0;j<charSet.length;++j) {
sValor=sValor.replaceAll(charSet[j], replaceSet[j]);
}
///System.out.println(sValor);
sValor = sValor.replaceAll("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>","");
org.xml.sax.InputSource inStream = new org.xml.sax.InputSource();
inStream.setCharacterStream(new java.io.StringReader(sValor));
DocumentBuilder b=factory.newDocumentBuilder();
Document cdataSection=b.parse(inStream);
child2=(Element) docOut.importNode(cdataSection.getDocumentElement(),true);
MainRoot.appendChild(child2);
}
}
}
docOut.appendChild(MainRoot);
String sResult = convertDocument_String(docOut);
out.write(sResult.toString().getBytes("UTF-8"));
out.close();
} catch (Exception ex){
this.getTrace().addDebugMessage(ex.toString());
}
}
Regards
Lucho.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pablo,
You can try to parse the content of TAG "return" (using DOM or SAX) and get the value of "Codigo" and "Mensaje" using an UDF.
Take a look at the following thread... there is an UDF code example.
http://scn.sap.com/message/2229578#2229578
Regards,
Daniel Rosa.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.