문제

For some reason I have tried to surround the parameters sExtraParameter, sExtraParameter2, sExtraParameter3 with <![CDATA[ ]]> string in order to get "pretty-printed" latin characters. But every time I check the xml output, it stills show bad parsed characters.

So, if is there another way to apply the CDATA to this parameters?

public static Element xslTransformJDOM(File xmlFile, String xslStyleSheet, String sExtraParameter, String sExtraParameterValue, String sExtraParameter2, String sExtraParameterValue2, String sExtraParameter3,String sExtraParameterValue3 ) throws JDOMException, TransformerConfigurationException, FileNotFoundException, IOException{

    try{

        Transformer transformer = TransformerFactory.newInstance().newTransformer(new   StreamSource(xslStyleSheet));
        transformer.setParameter(sExtraParameter, sExtraParameterValue);
        transformer.setParameter(sExtraParameter2, sExtraParameterValue2);
        transformer.setParameter(sExtraParameter3, sExtraParameterValue3);

        JDOMResult out = new JDOMResult();

        transformer.transform(new StreamSource(xmlFile), out);

        Element result = out.getDocument().detachRootElement();

        setSize(new XMLOutputter().outputString(result).length());

        return result;

    }
    catch (TransformerException e){
        throw new JDOMException("XSLT Transformation failed", e);
    }
}

edit:

I am following up a project from my boss, for these reason I have not the entire code to show you here.

도움이 되었습니까?

해결책

Maybe I have missed the question, but the API (http://docs.oracle.com/javaee/1.4/api/javax/xml/transform/Transformer.html#setParameter(java.lang.String, java.lang.Object)) for setParameter does not expect

value - The value object. This can be any valid Java object. It is up to the processor to provide the proper object coersion or to simply pass the object on for use in an extension.

  1. This could then vary by implementation, assuming you are using JDOM.
  2. There may be a CDATA xml element that would then be processed correctly. Maybe: http://www.jdom.org/docs/apidocs/org/jdom2/CDATA.html
  3. You could still think about setting the serializer settings to some sort of whitespace preservation. http://www.jdom.org/docs/apidocs.1.1/org/jdom/output/Format.TextMode.html
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top