1 Reply Latest reply: Aug 12, 2011 12:04 PM by maheshguruswamy RSS

    XML Transformation - Migration from JDK 1.4 to JDK 1.6

    882137
      Hi all,

      I am switching from JDK 1.4 to JDK 1.6 but my XSLT transformations are outputting different XML (although structurally sound). JDK 1.6 outputs the namespaces for each element rather than placing them at the top level node.

      I've included the settings and the code below. I expect that there is a feature or a way to handle this but I have not been able to find it now for several days.

      Any recommendations would be greatly appreciated.

      Regards
      Paul

      JDK1.4
      JAXP: loaded from fallback value: org.apache.xalan.processor.TransformerFactoryImpl
      JAXP: loaded from fallback value: org.apache.crimson.jaxp.SAXParserFactoryImpl


      <?xml version="1.0" encoding="UTF-8"?>
      <ex1:IE518 xmlns:xdata="http://www.edifecs.com/xdata/100" xmlns:exe="http://test.com/schemas/ex1/elements/v1" xmlns:ext="http://test.com/schemas/ex1/extypes/v1" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:ex1="http://test.com/schemas/ex1/MSG/v1">
      <ext:Common>
      <exe:SyntaxID>UNOC</exe:SyntaxID>
      <exe:MessageID>00000000000000</exe:MessageID>
      <exe:IEMessageType>MsgType</exe:IEMessageType>
      </ext:Common>
      <ext:Header>
      <exe:SpecificCircumstanceIndicator>B</exe:SpecificCircumstanceIndicator>
      <exe:Transit>0</exe:Transit>
      <exe:CommercialReferenceNumber>DHL11-7-43</exe:CommercialReferenceNumber>
      </ext:Header>
      </ex1:IE518>

      JDK 1.6
      JAXP: loaded from fallback value: com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
      JAXP: loaded from fallback value: com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl

      <?xml version="1.0" encoding="UTF-8"?>
      <ex1:IE518 xmlns:ex1="http://test.com/schemas/ex1/MSG/v1">
      <ecc:Common xmlns:ext="http://test.com/schemas/ex1/extypes/v1">
      <exe:SyntaxID xmlns:exe="http://test.com/schemas/ex1/elements/v1" >UNOC</ece:SyntaxID>
      <exe:MessageID xmlns:exe="http://test.com/schemas/ex1/elements/v1" >00000000000000</ece:MessageID>
      <exe:IEMessageType xmlns:exe="http://test.com/schemas/ex1/elements/v1" >MsgType</ece:IEMessageType>
      </ecc:Common>
      <ecc:Header xmlns:ext="http://test.com/schemas/ex1/extypes/v1">
      <exe:SpecificCircumstanceIndicator xmlns:exe="http://test.com/schemas/ex1/elements/v1" >B</ece:SpecificCircumstanceIndicator>
      <exe:CommercialReferenceNumber xmlns:exe="http://test.com/schemas/ex1/elements/v1" >DHL11-7-43</exe:CommercialReferenceNumber>
      </ecc:Header>
      </ex1:IE518>


      try {
           byte[] transformed;
           StreamSource inputData = new StreamSource( new ByteArrayInputStream( xml_ecs.getBytes( ) ) );

           FileInputStream xsltData = new FileInputStream( xsl_file_path );

           StreamSource transformationData = new StreamSource( xsltData );
           StreamResult streamResult = new StreamResult(new ByteArrayOutputStream( ));

           //create transformer factory
           TransformerFactory tFactory = TransformerFactory.newInstance( );
           Transformer transformer = tFactory.newTransformer( transformationData );

           //perform transformation
           transformer.transform( inputData, streamResult );
           transformed = ((ByteArrayOutputStream) (streamResult.getOutputStream( )))
                .toByteArray( );

           System.out.println ("TRANSFORMED OUTPUT [" + new String(transformed) + "]");
      }
      catch (TransformerException texsc) {
           System.out.println( "TransformerException caught: "
                     + texsc.getMessage() );
           throw texsc;
      }
      catch (Exception ex) {
           ex.printStackTrace();
           System.out.println(ex.getMessage());
      }