0
URL stringfile = getXsl("test.xml");
File originFile = new File(stringfile.getFile());

String xml = null;
ByteArrayOutputStream pdfStream = null;
try {
FileInputStream fis = new FileInputStream(originFile);
int length = fis.available();
byte[] readData = new byte[length];

fis.read(readData);
xml = (new String(readData)).trim();
fis.close();            
xml = xml.substring(xml.lastIndexOf("<HttpCommandList>")+17, xml.lastIndexOf("</HttpCommandList>"));
String[] splitxml = xml.split("</HttpCommand>");

for (int i = 0; i < splitxml.length; i++) {
    tmpxml = splitxml[i].trim() + "</HttpCommand>";
    System.out.println("splitxml:" +tmpxml);

    pdfStream = new ByteArrayOutputStream();
    pdf = new com.lowagie.text.Document();
    PdfWriter.getInstance(pdf, pdfStream);
    pdf.open();

    URL xslToUse = getXsl("test.xsl");

    // Here am using some utility class to transform                            
    // generate the XML needed by iText to generate the PDF using MessageBuffer contents
    String iTextXml = XmlUtil.transformXml(tmpxml.toString(), xslToUse).trim();

    // generate the PDF document by parsing the specified XML file
    XmlParser.parse(pdf, new ByteArrayInputStream(iTextXml.getBytes()));

}

For the above code, during the XmlParser am getting java.net.malformedURL exception : no protocol Am trying to generate the pdf document by parsing the specified xml file.

2
  • Can you print stringfile and xslToUse and let us know what's the output? Commented Dec 22, 2014 at 10:55
  • 2
    You need to upgrade iText and XML Worker. This is never going to work properly if you are using the obsolete com.lowagie.* packages. (If you doubt me, take a look at my name.) Commented Dec 22, 2014 at 11:27

1 Answer 1

0

We could need the actual xml-file to decide what is missing. I expect, that there is no protocol defined, just like this:

192.168.1.2/         (no protocol)
file://192.168.1.2/  (there is one)

And URL seems to need one.

Also try:

new File("somexsl.xlt").toURI().toURL();

See here and here.

It always helps spoilering the complete stacktrace. No one knows, where the exception actually occured, if you dont post the line numbers.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.