on 02-04-2013 8:51 PM
Hi All,
I am wondering if anyone can help me please.
I have a requirement in which I have to remove <![CDATA[<?xml version="1.0" encoding="UTF-8"?> and </Invoice]]> from the XML.
I have tried JAVA Mapping but getting illegal index error 46
I am using the following in JAVA
bw.write(line.replaceAll("<!CDATA <?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""));
bw.write(line.replaceAll("</Invoice>]]>", "</Invoice>"));
Error in PI
java.util.regex.Pattern SyntaxException
Illegal character range near index 43
<![CDATA[<?xml version="1.0" encoding="UTF-8"?>
Regards,
Iqbal
Hello,
I think u want to extract string inside cdata?
If yes then chk my reply in below link:
http://scn.sap.com/thread/3294546
Thanks
Amit Srivastava
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amit,
Could you please tell me how to remove CDATA tag through xslt.
Here is my Source XML
<?xml version="1.0" encoding="UTF-8"?>
<DocumentBundle xmlns="http://abc.com.com/api/1.0">
<Document type="invoice" id="f11cc168-8764-4fbb-a783-aa893f6b3e60"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
<Invoice>
<cbc:EndpointID schemeID="GB:VAT">GB122222343</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="GB:CNO">11111111</cbc:ID>
</Invoice>]]>
I want the output to be like this
<?xml version="1.0" encoding="UTF-8"?>
<DocumentBundle xmlns="http://abc.com.com/api/1.0">
<Document type="invoice" id="f11cc168-8764-4fbb-a783-aa893f6b3e60
<Invoice>
<cbc:EndpointID schemeID="GB:VAT">GB122222343</cbc:EndpointID>
<cac:PartyIdentification>
<cbc:ID schemeID="GB:CNO">11111111</cbc:ID>
</Invoice>
Regards,
Iqbal
Hi.
Try with this.
Document docOut = null;
private void execute(InputStream in, OutputStream out) throws StreamTransformationException {
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builderel=factory.newDocumentBuilder();
Document docIn=builderel.parse(in);
docOut=builderel.newDocument();
String sResult = null;
Node node;
NodeList nListRec = docIn.getElementsByTagName("DocumentBundle");
node = nListRec.item(0);
Node clon = docOut.importNode(node,true);
docOut.appendChild(clon);
sResult = convertDocument_String(docOut);
sResult = sResult.replace("<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>","");
sResult = sResult.replace("]]>","");
out.write(sResult.toString().getBytes("UTF-8"));
out.close();
} catch (Exception ex) {
ex.printStackTrace();
System.out.println("Error ---" + ex.getMessage().toString() );
}
}
public static String convertDocument_String(Document Doc){
String sResult ="";
StringWriter writer = new StringWriter();
try {
DOMSource domSource = new DOMSource(Doc);
StreamResult result = new StreamResult(writer);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
transformer.transform(domSource, result);
} catch (Exception ex) {
ex.printStackTrace();
}
sResult = writer.toString();
return sResult;
}
This just isn't working for me. What I have is XML like below. But when I build the java map, I replace "DocumentBundle" with "Data", run this through the OM test it seems to crash on line 08: Document docIn=builderel.parse (in) with Premature end of file. Any suggestions? FYI I am not a java developer but I know many other development languages. Thanks for any help.
<enab:ExportDataResponse xmlns:enab="enablon">
<Data><![CDATA[<?xml version="1.0" encoding="UTF-16" standalone="yes" ?>
<Document>
<Record>
<EmployeeID>ID000006150265</EmployeeID>
<ApplicationUser><None></ApplicationUser>
<LastName>Shi</LastName>
<FirstName>Nansun</FirstName>
</Record>
</Document>]]>
</Data>
</enab:ExportDataResponse>
Hi Iqbal,
I guess we can use XSLT mapping to fix this issue.
Can you please send the souorce XML and the resultant XML you are expecting.
Thanks,
Ashish
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi.
Try with this. Use only replace instead replaceAll.
Regards
Lucho
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
strange it's not working for me.
Also there are spaces in between
The Actual string is
bw.write(line.replaceAll("<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""));
I have defined line as a String and when I am trying to change it to char it's giving me an error.
I am using eclipse.
here is the code which I am using
public void execute(InputStream arg0, OutputStream arg1)
throws StreamTransformationException {
String line = null;
BufferedReader br = new BufferedReader(new InputStreamReader(arg0));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(arg1));
// Get reference to mapping trace
trace = (AbstractTrace)map.get(StreamTransformationConstants.MAPPING_TRACE);
trace.addInfo("Processing message");
try {
//Read all lines of input stream arg0
while ((line=br.readLine()) != null) {
bw.write(line.replaceAll("<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>", ""));
}
bw.flush();
br.close();
bw.close();
} catch (IOException ioe) {
trace.addWarning("Could not process source message");
throw new RuntimeException(ioe.getMessage());
}
trace.addInfo("Processing completed successfully");
}
}
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
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.