0

I have an xml with some data and after using filter activity in IBM Cast Iron I am getting below xml in place of badxml. This causing an exception.

badXml.xml

<?xml version="1.0" encoding="UTF-8"?>
<RemitSchemaData xmlns=""><?xml version="1.0"?>


</RemitSchemaData>

Now to resolve this I am trying to use xslt to remove the duplicate xml declaration inside my xml tag. Please help me on how to do this.

Input

<?xml version="1.0" encoding="UTF-8"?>
<RemitSchemaData xmlns=""><?xml version="1.0"?>


</RemitSchemaData>

Expected Ouput

<?xml version="1.0" encoding="UTF-8"?>
<RemitSchemaData/>
  • 1
    Using XML tools like XSLT to process something that is not XML is a difficult task, you might rather want to look into avoiding the generation of that mal-formed markup. As for trying it with XSLT, you would need to use `unparsed-text` and regular expression `replace` to try to remove the XML declaration, however then with pure XSLT 2 you would already have troubles to return the text you have changed as XML, unless the tool chain allows the use of `disable-output-escaping` – Martin Honnen Mar 05 '18 at 20:38
  • Thank You for your inputs. This Malformed xml is generated by IBM Cast Iron tool and cannot be avoided. I was hoping I can use XSLT to reform it into a valid xml. – sandeep kairamkonda Mar 05 '18 at 21:04
  • As Martin Honnen said, it's doable in XSLT, but it'll be ugly. XSLT excels in transforming XML, and your textual data is not XML. See the duplicate link for a prioritized list of options for dealing with bad "XML". – kjhughes Mar 05 '18 at 21:55

0 Answers0