I am trying to develop an endpoint which should accept xml data and produce pdf with it. I have created the xsd file which I am using to generate JAXB Classes
and I declared the xs type of request to be string like this:
<xs:element name="producepdf-request">
<xs:complexType>
<xs:sequence>
<xs:element name="xmlData" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
but when I pass the xml data to this endpoint as String
then there is a lot of invald xml
characters which are causing IOException
. I create the required xml data to call this endpoint like this:
File xmlDocument = new File("C:\\Users\\stu\\Desktop\\fileName.xml");
String xmlData = FileUtils.readFileToString(xmlDocument, "UTF-8");
and clear invalid characters:
String xml10pattern = "[^"
+ "\u0009\r\n"
+ "\u0020-\uD7FF"
+ "\uE000-\uFFFD"
+ "\ud800\udc00-\udbff\udfff"
+ "]";
xmlData = xmlData.replaceAll(xml10pattern, "");
then pass it to the endpoint. The problem is that I still get exceptions due to invalid characters. So what is the better way of solving this issue? Is there a type to declare the request
type on xsd
level so that I don't have to worry about invalid characters, or is there a better way to read the xml file from the file system?
Thanks.