Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8067704

DOMSource.setSystemId doesn't work expected when use DOMSource as Transformer source

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 9
    • xml
    • None

      DOMSource and StreamSource both provides setSystemId API for setting base ID for file reference. When using StreamSource as InputSource for Transformer, the base ID get resolved

      FileOutputStream fos = new FileOutputStream("dom.out");
              InputStream xmlStream = new FileInputStream("SystemIdImpIncl.xml");
              TransformerFactory factory = TransformerFactory.newInstance();
              Source xslSource = new StreamSource(new InputStreamReader(new FileInputStream("/test/SystemIdImpIncl.xsl")));
              xslSource.setSystemId("file:///test");
              
              Source xmlSource = new StreamSource(xmlStream);
              factory.newTemplates(xslSource).newTransformer().
                      transform(xmlSource, new StreamResult(fos));

      DOMSource doesn't work for this case, the file wasn't correctly parsed and it doesn't throw any error.
             FileOutputStream fos = new FileOutputStream("dom.out");
              InputStream xmlStream = new FileInputStream("SystemIdImpIncl.xml");
              TransformerFactory factory = TransformerFactory.newInstance();
              DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
              Node xslNode = docBuilder.parse(new InputSource("file:///test/SystemIdImpIncl.xsl"));
              Source xslSource = new DOMSource(xslNode);
              xslSource.setSystemId("file:///test");
              
              Source xmlSource = new StreamSource(xmlStream);
              factory.newTemplates(xslSource).newTransformer().
                      transform(xmlSource, new StreamResult(fos));

            joehw Joe Wang
            tyan Tristan Yan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: