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.

parakmiakos
  • 2,896
  • 8
  • 26
  • 42
Nithya
  • 9
  • 1
  • Can you print stringfile and xslToUse and let us know what's the output? – SMA Dec 22 '14 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.) – Bruno Lowagie Dec 22 '14 at 11:27

1 Answers1

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.

Community
  • 1
  • 1
Simon K.
  • 390
  • 1
  • 5
  • 21